Skip to content

Commit

Permalink
Fix AssemblyResolve in .NET Core
Browse files Browse the repository at this point in the history
  • Loading branch information
ricaun committed Apr 4, 2024
1 parent 946873d commit 552f227
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 7 deletions.
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,20 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Fixed
- Fix `Installation` Application issue.
- Fix `Timeout` issue with `testsFinishedForceToEnd`.
### Updated
- Update `ricaun.Revit.Installation`
### Command
- Update `ricaun.Revit.Installation` to `1.1.2`
- Update `debugger` with debug logs.
- Update `Command` with `SemanticVersion`.
### Application
- Fix `AssemblyResolve` in `.NET Core` updated `AppDomainExtension`.
### Shared
- Update `NamedPipeWrapper.Json` to `1.7.0`
### TestAdapter
- Update `TestAdapter` with debug logs.
- Update `TestAdapter` with `PackageTags`
- Update `TestAdapter` with `PackageLicenseFile`


## [1.3.0] / 2024-03-28
### Features
- Readme information to wiki.
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project>
<PropertyGroup>
<Version>1.3.1-beta.1</Version>
<Version>1.3.1-rc</Version>
</PropertyGroup>
</Project>
20 changes: 20 additions & 0 deletions ricaun.RevitTest.Application/Extensions/AppDomainUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ internal static class AppDomainUtils
/// <returns></returns>
public static AppDomainExtension.DelegatesDisposable AssemblyResolveDisposable()
{
#if DEBUG
var resolveEventHandler = AppDomain.CurrentDomain.GetResolveEventHandler();
Console.WriteLine($"Debug Domain >> {AppDomain.CurrentDomain.FriendlyName}");
Console.WriteLine($"Debug Assembly >> {typeof(AppDomainUtils).Assembly.FullName}");
Console.WriteLine($"Debug Location >> {typeof(AppDomainUtils).Assembly.Location}");
Console.WriteLine($"Debug GetResolveEventHandler >> {resolveEventHandler}");
if (resolveEventHandler is not null)
{
Console.WriteLine($"Debug GetInvocationList >> {resolveEventHandler.GetInvocationList().Length}");
}
#endif
return AppDomain.CurrentDomain.GetAssemblyResolveDisposable().NotRemoveDelegatesAfterDispose();
}
}
Expand All @@ -25,12 +36,21 @@ internal static class AppDomainExtension
/// <returns></returns>
public static ResolveEventHandler GetResolveEventHandler(this AppDomain appDomain)
{
#if NETFRAMEWORK
var fieldName = "_AssemblyResolve";

var fieldInfo = appDomain.GetType()
.GetField(fieldName, BindingFlags.Instance | BindingFlags.NonPublic);

return fieldInfo?.GetValue(appDomain) as ResolveEventHandler;
#elif NET
var fieldName = "AssemblyResolve";

var fieldInfo = typeof(System.Runtime.Loader.AssemblyLoadContext)
.GetField(fieldName, BindingFlags.Static | BindingFlags.NonPublic);

return fieldInfo?.GetValue(null) as ResolveEventHandler;
#endif
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
<PackageReference Include="Newtonsoft.Json" Version="9.*" IncludeAssets="build; compile" PrivateAssets="All">
<NoWarn>NU1903</NoWarn>
</PackageReference>
<PackageReference Include="Revit_All_Main_Versions_API_x64" Version="$(RevitVersion).*-*" IncludeAssets="build; compile" PrivateAssets="All" />
<PackageReference Include="Revit_All_Main_Versions_API_x64" Version="$(RevitVersion).*" IncludeAssets="build; compile" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion ricaun.RevitTest.Console/ricaun.RevitTest.Console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="ricaun.Revit.Installation" Version="*-*" />
<PackageReference Include="ricaun.Revit.Installation" Version="*" />
<PackageReference Include="Microsoft.VisualStudio.Interop" Version="*" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion ricaun.RevitTest.Shared/ricaun.RevitTest.Shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="NamedPipeWrapper.Json" Version="*-*" />
<PackageReference Include="NamedPipeWrapper.Json" Version="*" />
<PackageReference Include="ricaun.NUnit" Version="*" />
</ItemGroup>

Expand Down
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion ricaun.RevitTest.Tests/ricaun.RevitTest.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@

<ItemGroup>
<PackageReference Include="ricaun.Revit.Async" Version="*" />
<PackageReference Include="Revit_All_Main_Versions_API_x64" Version="$(RevitVersion).*-*" IncludeAssets="build; compile" PrivateAssets="All" />
<PackageReference Include="Revit_All_Main_Versions_API_x64" Version="$(RevitVersion).*" IncludeAssets="build; compile" PrivateAssets="All" />
</ItemGroup>

</Project>

0 comments on commit 552f227

Please sign in to comment.