-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AssemblyDependencyResolver raises exception when hosting .NET using using Mscoree.h #39167
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
Tagging subscribers to this area: @vitek-karas, @swaroop-sridhar, @agocke |
This is currently by design. The AssemblyDependencyResolver currently only works if the runtime is hosted via |
Well I cannot use that option, because I'm using non default appDomainFlags and there is no way to provide them using hostpolicy. |
What non-default flags do you use (and if you can provide that info - why)? I want to figure out if there's a scenario which |
|
I'll try to answer as I investigate:
This is on by default when using the new initialization APIs (which
I don't know the answer to this - @janvorli would you know if there's a way to get this behavior without setting the flag on AppDomain via native code?
The config path is just a way to find the .NET Core runtime, you are doing this manually now. If you need to use self-contained runtime (meaning you ship the runtime with the app) - this is supported for application in 3.1, but if you need to load the managed code as "components" into otherwise native app then something similar was added in .NET 5. See #35465 for a detailed discussion on a very similar requirement. The new functionality introduced as part of this issue should be a solution for you - see https://github.com/dotnet/runtime/blob/master/docs/design/features/native-hosting.md#calling-managed-function-net-5-and-above for the new API description. Note that with self-contained apps the config file is effectively optional anyway.
It is possible - https://github.com/dotnet/runtime/blob/master/docs/design/features/native-hosting.md#inspect-and-modify-host-context - you can call
|
Thank you so much for such detailed answer!
Everything else looks like working correctly. Except that I got strange errors everywhere in WPF that I didn't have before. Could it be related to hdt_load_assembly_and_get_function_pointer function that loading assemblies into secondary ALC? If yes, is there any other way to load assembly into default ALC by specifying assembly file name? I did read about hdt_get_function_pointer but there is no way to specify assembly path. Our application has many plugins and they are in different directories and adding them to APP_PATHS is huge overkill. And I believe it is not possible to modify APP_PATHS after runtime is initialized but our application allows to download plugin while application is running. |
Running WPF in secondary ALC is known to have issues - some of it might be possible to overcome with https://docs.microsoft.com/en-us/dotnet/api/system.runtime.loader.assemblyloadcontext.currentcontextualreflectioncontext?view=netcore-3.1 but I don't know if it solves all known problems. We don't have a first class support for loading assemblies by path into default ALC - simply didn't get to it yet (and it's also a bit tricky as using
I know this is not exactly nice, but currently it's the only solution I can think of (until there's direct support for this in the .NET Core). |
I created new assembly and it has only one class, one method and one delegate. Then I got pointer to that method via
and in DotNetTools I have
that will load assembly from path and create root object for our application to use. I seems to work and WPF works correctly.
|
Changing 5.0.0-preview to 5.0.0 is perfectly fine - final .NET 5 SDK will generate 5.0.0 anyway. In your solution I assume you called So I would more or less keep the code on the managed side you have - I would just build it as an application (.exe) with an empty main (current limitation of being able to only do self-contained apps, not components). Then I would publish this as self-contained |
I would like to briefly explain structure of our application. We have main native application and many different modules. Some of these modules are native, some are written in .NET Framework. All communications between modules done via COM interfaces (even it is not 100% COM as there is no interfaces and co-classes registrations etc). So every module has factory function that returns interface to it and further communications done via this interface. Application does not load all modules at the same time, because it will take a lot of time and most of the customers does not need even 10% of modules. So if customer would like for example to import or export file, then that module will be loaded (if it was not loaded before) and action is executed via that root interface (or one of interfaces that root interface returns).
Thank you again for helping me with this! |
|
Thank you again for your help! Should I to create new issue for APPDOMAIN_IGNORE_UNHANDLED_EXCEPTIONS for hostfxr or should I wait? This is my last problem with hostfxr. |
New issue might be better. |
I think this issue/question has been answered. The one remaining question is tracked separately in #39587. |
Description
Creating instance of AssemblyDependencyResolver throws exception "Hostpolicy must be initialized and corehost_main must have been called before calling corehost_resolve_component_dependencies" when native host uses Mscoree.h to load .NET 5 runtime.
Steps:
Expected behavior: I believe during host initialization I provided enough information to allow AssemblyDependencyResolver work
Actual behavior: Exception is raised in corehost_resolve_component_dependencies
Configuration
The text was updated successfully, but these errors were encountered: