Purpose: from a .NET 4.7 console application, using reflection with Assembly.GetType (), I try to extract a class class of netstandard 2.0 class from Assembly X. Then I want to instantiate this type using Activator.CreateInstance (),
What I'm trying to do: It does not , however, the assembly has a dependency on X Netstandard 2.0. To get a type, you need to load a custom dependency in the application domain. Therefore, when AppDomain requests a custom assembly through the AssemblyResolve event, I simply load the dll as follows:
var netStandardDllPath = @"C:\Users\xxx\.nuget\packages\NETStandard.Library.2.0.0-preview1-25301-01\build\netstandard2.0\ref\netstandard.dll";
return Assembly.LoadFrom(netStandardDllPath);
Which throws:
System.BadImageFormatException: "Could not load file or assembly" file: /// C: \ Users \ vincent.lerouvillois.nuget \ packages \ NETStandard.Library.2.0.0-preview1-25301-01 \ build \ netstandard2.0 \ ref \ netstandard.dll 'or one of its dependencies. Reference assemblies must not be loaded to execute. They can only be loaded in the boot loader context for reflection only. (Exception from HRESULT: 0x80131058) '
Internal exception: BadImageFormatException: Unable to load the reference assembly for execution.
What I know: I know that they want us to load the DLL using Assembly.ReflectionOnlyLoadFrom. But that will not allow me to instantiate the type using Activator.CreateInstance (). See Microsoft official post
, Nuget NETStandard.Library 2.0.0-preview1-25301-01 NETStandard.Library.NETFramework 2.0.0-preview1-25305-02 , netstandard 2.0, .
: - , DLL , , , , ? DLL ?