Replies: 1 comment
-
Basically the recommendation is to use hostfxr_initialize_for_dotnet_command_line (which should fix the app base issue as well I think) and then use the get_function_pointer to get a pointer to the managed code - the default load context. We currently don't have functionality which would allow loading assemblies into the default load context via the hosting APIs (other than CPP/CLI which does this). /cc @elinor-fung |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
In my scenario I have:
MyManaged.dll uses DllExport/.export technique for exposing methods for unmanaged application.
This works like this:
After calling
myExportedProc
the shim locates .NET Framework, initializes clr, does some replacements in export code (JMPs of "MyExportedProcedure" are replaced with JMP to clr code).Anyway, it works for me for ages.
Now I'm trying to switch to .NET 6.
I compiled MyManaged.dll for .NET 6 with DllExport/.export.
I used DllExport library from nuget.
Additionally I had to create new MyManaged.Host.DLL that will start and initialize coreclr.
I did that by using hostfxr.
In general, it works.
I had to do additional stuff like:
The problem I have is AssemblyLoadContext.
The code below loads MyManaged.dll and referenced assemblies in isolated AssemblyLoadContext.
Afterwards I call:
MyExportedProcedure loads other assemblies located in bin directory and they are loaded in Default AssemblyLoadContext.
This way I'm getting some of my assemblies loaded twice, which finally leads to errors.
Is it possible to force all my dotnet assemblies to be loaded in the same AssemblyLoadContext?
I suppose that I cannot use
load_assembly_and_get_function_pointer_fun
, because it isolates the requested assembly by default.I tried to bypass
load_assembly_and_get_function_pointer_fun
step, however then I'm getting exception when callingmyExportedProc()
.Should I try to speak with coreclr.dll directly? I see that it has few useful exports:
Here is my playground source code:
https://github.com/podprad/misc_public/tree/main/playgrounds/csharp/Net6Hosting
Update
I made it working by using coreclr.dll directly.
Best regards,
Michal
Beta Was this translation helpful? Give feedback.
All reactions