dimanche 27 décembre 2020

Can NET Framework 4.7.2 apps load at runtime NET Core 5.0 library DLLs?

I'm starting to port some of my NET Framework 4.7.2 class libraries to NET Core 5.0. The host Framework app dynamically discovers and runs Assembly.Load on the NET Core library ok. But when I try to do a Assembly.GetType(NET50Namespace.Classname) operation on the loaded assembly, it fails and returns null with the error:

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

It looks like it is trying to load the NET Core 5.0.0.0 runtime, which I do have installed. I checked with the console command dotnet --list-runtimes and both the NETCore and WindowsDesktop runtimes are installed ok:

c> dotnet --list-runtimes

Microsoft.NETCore.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

I'm stuck.

Q1. Is it legal/possible for a Framework 4.7.2 app to dynamically load and run a NETCore 5.0 DLL? I was trying to port small pieces of my app to NET50 as a first step. But it is not working, and I might be trying to do the impossible.

Q2. If it is ok for Framework to load/call NET50 DLLs, what am I doing wrong, and how can I make the GetType call work so that I can instantiate and call the NET50 class library?

Thank you.





Aucun commentaire:

Enregistrer un commentaire