Reputation: 5791
I have a legacy assembly that is still on .NET Framework 4.8 and references System.Windows.Forms.dll (for non-UI reasons, actually) and I would like to use it inside a .NET Interactive Notebook through also existing code that loads this assembly using Assembly.LoadFrom
.
However, if I do that, I end up getting an exception Could not load file or assembly 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.
. So in my opinion, essentially the runtime is not looking into the .NET 4 GAC, because it is not a .NET 4 CLR and then expecting the assembly to be located in the same folder.
In applications that are under control, we had some good success simply changing the target framework moniker to net6.0-windows
in that case, but recompile obviously is not an option for interactive notebooks.
I have seen that there is a runtimeconfig.json in the Nuget cache folder for the entry DLL:
{
"runtimeOptions": {
"tfm": "net6.0",
"frameworks": [
{
"name": "Microsoft.NETCore.App",
"version": "6.0.0"
},
{
"name": "Microsoft.AspNetCore.App",
"version": "6.0.0"
}
],
"configProperties": {
"System.GC.Server": true,
"System.Reflection.Metadata.MetadataUpdater.IsSupported": false,
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
}
}
}
However, changing the tfm setting there did not seem to work, either. What am I doing wrong?
Upvotes: 2
Views: 269
Reputation: 5791
I forgot to paste the solution here in case anybody runs into the same problem. I actually just copied the assembly from the GAC into the application folder and then, .NET Core was able to find the assembly.
Upvotes: 0