none
Unable to load a .NET Core DLL from a .NET Framework DLL using Assembly.Load() RRS feed

  • Question

  • Hello,

    I load a .NET Core DLL from a .NET Framework DLL using Assembly.Load(), it work when I select in the .NET Core DLL project properties version 1.1, if I choose .NET Core 2.0 or later, it is impossible to load the DLL?

    I have this message error :

    Could not load file or assembly 'System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified

    Thanks

    Friday, September 20, 2019 7:27 AM

All replies

  • .NET framework using anything .NET Core is incompatible.

     

    Friday, September 20, 2019 10:33 AM
  • It's incompatible but .NET Core 1.1 work ?

    I think .NET Framework 4.8 use System.Runtime 4.0.0.0

    and .NET Core 2.2  use System.Runtime 4.2.1.0

    MS should update .NET Framemork to System.Runtime 4.2.1.0



    • Edited by pol_2095 Friday, September 20, 2019 7:07 PM
    Friday, September 20, 2019 6:44 PM
  • You can't load the assembly in the usual way, but you can use "ReflectionOnlyLoad" - this requires that you also wire up event handlers for the following events:

    System.AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve

    System.Runtime.InteropServices.WindowsRuntime.WindowsRuntimeMetadata.ReflectionOnlyNamespaceResolve

    Doing this allows you to inspect these assemblies.


    Convert between VB, C#, C++, & Java (http://www.tangiblesoftwaresolutions.com)
    Instant C# - VB to C# Converter
    Instant VB - C# to VB Converter

    Friday, September 20, 2019 10:21 PM
  • I tried this code but I have the same message error :

    AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += (sender, eventArgs) => Assembly.ReflectionOnlyLoad(eventArgs.Name);
    WindowsRuntimeMetadata.ReflectionOnlyNamespaceResolve += (sender, eventArgs) =>
    {
        string path =
            WindowsRuntimeMetadata.ResolveNamespace(eventArgs.NamespaceName, Enumerable.Empty<string>())
                .FirstOrDefault();
        if (path == null) return;
    
        eventArgs.ResolvedAssemblies.Add(Assembly.ReflectionOnlyLoadFrom(path));
    };
    
    Assembly SampleAssembly = Assembly.ReflectionOnlyLoadFrom(pathDLL);
    Type[] types = SampleAssembly.GetExportedTypes();
    foreach (Type type in types)
    {
        Console.WriteLine(type);
    }


    • Edited by pol_2095 Saturday, September 21, 2019 6:55 AM
    Saturday, September 21, 2019 6:49 AM
  • For the ReflectionOnlyAssemblyResolve handler, try:

    AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += (sender, eventArgs) => {
    	string assemblyLongName = AppDomain.CurrentDomain.ApplyPolicy(args.Name);
    	return Assembly.ReflectionOnlyLoad(assemblyLongName);
    }
    


    Convert between VB, C#, C++, & Java (http://www.tangiblesoftwaresolutions.com)
    Instant C# - VB to C# Converter
    Instant VB - C# to VB Converter

    Saturday, September 21, 2019 2:11 PM
  • I added System.Runtime.dll (C:\Program Files\dotnet\shared\Microsoft.NETCore.App\2.2.7) in my app folder, and I have this message error :

    System.IO.FileNotFoundException: Could not load file or assembly 'System.Private.CoreLib, Version=4.0.0.0, Culture=neutral,
    	PublicKeyToken=7cec85d7bea7798e' or one of its dependencies. The system cannot find the file specified





    • Edited by pol_2095 Sunday, September 22, 2019 11:48 AM
    Saturday, September 21, 2019 2:47 PM
  • Hi pol_2095,

    Thank you for posting here.

    According to your question, I suggest that you can report a problem in Developer Community forum for more help.

    Thank you for your understanding.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, September 23, 2019 8:08 AM
    Moderator