AaronRobinsonMSFT / DNNE

Prototype native exports for a .NET Assembly.
MIT License
406 stars 41 forks source link

.NET library dependencies fail to load? #56

Closed jeffason closed 3 years ago

jeffason commented 3 years ago

I've been working on getting a .NET5 library (e.g. SimulationExports.dll) to work properly when called from native. This all works until the code requires an additional .NET5 library dependency (e.g. SimulationCore.dll) at which point I get:

Unhandled exception. System.TypeInitializationException: The type initializer for 'SimulationExports' threw an exception.
 ---> System.IO.FileNotFoundException: Could not load file or assembly 'SimulationCore, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.

In my case SimulationExports.dll and SimulationCore.dll sit side-by-side along with SimulationExports.runtimeconfig.json

AaronRobinsonMSFT commented 3 years ago

@jeffason Thanks for reaching out. If your main exports assembly has dependencies then its .deps.json file will also need to be deployed. Can you verify that is being generated when building SimulationExports.dll?

jeffason commented 3 years ago

The .deps.json is being generated and deployed but I noticed that the dependency it is complaining about isn't a direct reference in SimulationExports.csproj, but is a dependency of another dependency. Should nested dependencies resolve correctly? I am going to do a quick test by explicitly listing all libraries as dependencies in the parent SimulationExports project and see if I get a different result

jeffason commented 3 years ago

Actually, I just went and looked at SimulationExports.csproj and it does have explicit project dependencies to the .dll in question but it is not listed in the generated .deps.json file - any ideas?

AaronRobinsonMSFT commented 3 years ago

Actually, I just went and looked at SimulationExports.csproj and it does have explicit project dependencies to the .dll in question but it is not listed in the generated .deps.json file - any ideas?

@jeffason That's no good. That issue seems like a problem with the SDK generation of the .deps.json. Can you try removing DNNE from the project and see if it has an impact. If the same behavior exists I would suggest filing an issue on https://github.com/dotnet/sdk @vitek-karas any other ideas here?

jeffason commented 3 years ago

cross-linking the issue I opened in the other repo - https://github.com/dotnet/sdk/issues/14946

jeffason commented 3 years ago

A workaround linked in dotnet/sdk#14946 seems to fix my issue with the faulty *.deps.json so I think this issue can be closed. I'll open a new issue if I run into anything else. Thanks for your help and great work on DNNE!