I'm loading a .NET framework DLL from an OEM's website into a .NET 6.0 wrapper DLL.
Then I load that wrapper into my .NET 6.0 Winforms app:
- App (.NET6.0) uses
- DLL (.NET6.0) uses
- DLL (.NET framework)
You can see my code here:
https://github.com/pauldeboer1987/MCCDAQ_Wrapper
I get an error:
Could not load file or assembly 'XXX, Version=1.0.9.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified
But if I include a reference to DLL (.NET6.0) in App (.NET6.0), and still load it dynamically, it works.
The difference is the .deps.json
- it lists the dependencies of the DLL (.NET6.0).
Building the app without reference to the DLL (.NET6.0) and then replacing the deps.json
file, makes it work.
See the yesref and noref bins in my repo
I think it must be something about how I use AssemblyLoadContext
, but I don't know how to use it to load the dependencies as .NET framework. Or whatever is the difference.
I'm wrapping the MCCDAQ dll from https://www.mccdaq.com/Software-Downloads
I expect to be wrapping many others, but this is just my example. I think any other .NET framework dll would cause this problem, but I'm not sure.