Native -> CLI -> Managed dll leading to EEFileLoadException #70736
Replies: 1 comment 8 replies
-
.NET Runtime (as oppose to .NET Framework runtime) does not probe for files on disk. It relies on This is further complicated by the fact that you're loading the runtime from C++/CLI first. In .NET 6 the default behavior is to load only the core frameworks into the default load context, the C++/CLI assembly and all of its non-framework dependencies are loaded into a secondary load context. So in this case the default load context can only resolve assemblies from the framework (So basically In .NET 7 we changed this default and in this case the C++/CLI is loaded into the default load context which means that the default context will be able to resolve all of framework, the C++/CLI assembly and its dependencies. The dependencies of the C++/CLI assembly are determined by loading the So if the assembly you're trying to load was not part of the component during build (typically either You can customize this via several different callbacks the runtime provides, the most typical for the default load context would be to add an event handler to the Detailed description of the assembly resolution algorithm can be found here: https://docs.microsoft.com/en-us/dotnet/core/dependency-loading/loading-managed (there are other related docs near it in the TOC as well). |
Beta Was this translation helpful? Give feedback.
-
I'm hitting the same file load exception in two different scenarios.
I wasn't sure if any of this was related to
#61105
C++/CLI assembly is loaded into isolated AssemblyLoadContext (IsolatedComponentLoadContext) in .NET 6
I have also tried this in .NET preview 7.
My mixed cli dll is called oqkern.
If I call into it, and then access a standard .net api things work. E.g. something that just works with managed strings or DateTime etc.
But if I call into it and it tries to access stuff from another custom c# dll in the same folder (e.g. Bentley.APM.Settings ) then if fails to load this dll.
Under .NET Preview 7 I am able to start debugging into the assembly binder code and I can see that in BindAssemblyByProbingPaths that pBindingPaths is an empty list.
I'm wondering if what I am trying to do is supported or what the best way for me to achieve my goals is.
I'm not sure if I have to get into something complicated like:
Write a custom .NET host to control the .NET runtime from your native code
https://docs.microsoft.com/en-us/dotnet/core/tutorials/netcore-hosting
Or if I'm just missing something obvious.
I'll mention @vitek-karas and @elinor-fung as you both seemed very active in the discussions around the c++/cli assembly load context.
Thanks for your time,
Derek
Beta Was this translation helpful? Give feedback.
All reactions