Skip to content

Commit

Permalink
Fixed #127. 'Failed to resolve assembly...' when .NET Standard
Browse files Browse the repository at this point in the history
  • Loading branch information
3F committed Dec 12, 2019
1 parent 8c9ab72 commit e5366db
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
25 changes: 25 additions & 0 deletions RGiesecke.DllExport/DisabledAssemblyResolver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//# Author of original code ([Decompiled] MIT-License): Copyright (c) 2009-2015 Robert Giesecke
//# Use Readme & LICENSE files for details.

//# Modifications: Copyright (c) 2016-2019 Denis Kuzmin < [email protected] > GitHub/3F
//$ Distributed under the MIT License (MIT)

using Mono.Cecil;

namespace RGiesecke.DllExport
{
/// <summary>
/// Implements disabled assembly resolving.
/// Related issue: https://github.com/3F/DllExport/issues/127
///
/// For issue127 we can also use DefaultAssemblyResolver.AddSearchDirectory(),
/// But we don't actually need any assembly resolving in our case at all.
/// </summary>
internal sealed class DisabledAssemblyResolver: DefaultAssemblyResolver
{
public override AssemblyDefinition Resolve(AssemblyNameReference name)
{
return null; // It will be considered as `resolved = false` due to internal ResolutionException processing in cecil.
}
}
}
7 changes: 6 additions & 1 deletion RGiesecke.DllExport/ExportAssemblyInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,12 @@ public AssemblyDefinition LoadAssembly(string fileName)
return AssemblyDefinition.ReadAssembly
(
fileName,
new ReaderParameters(ReadingMode.Immediate) { InMemory = true, ReadWrite = true }
new ReaderParameters(ReadingMode.Immediate)
{
InMemory = true,
ReadWrite = true,
AssemblyResolver = new DisabledAssemblyResolver()
}
);
}

Expand Down
1 change: 1 addition & 0 deletions RGiesecke.DllExport/RGiesecke.DllExport.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<Compile Include="DisabledAssemblyResolver.cs" />
<Compile Include="PeCheckType.cs" />
<Compile Include="DllExportLogginCodes.cs" />
<Compile Include="DllExportServiceProviderExtensions.cs" />
Expand Down

0 comments on commit e5366db

Please sign in to comment.