Skip to content
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

Direct assemblies away from IsolatedComponentLoadContext towards a single AssemblyLoadContext #32851

Closed
obiwanjacobi opened this issue Feb 26, 2020 · 1 comment
Labels
area-AssemblyLoader-coreclr untriaged New issue has not been triaged by the area owner

Comments

@obiwanjacobi
Copy link

obiwanjacobi commented Feb 26, 2020

Moving forward from #32769, I am trying to load a managed plugin assembly into a mixed C++/CLI dll that is in charge of gathering all the plugin's dependencies. I am porting this code from Full-Fx to netcore3.1 so I replaced my Assembly::Load calls with AssemblyLoadContext::LoadAssemblyXxxx calls after reading more about AssemblyLoadContext.

I also hook into the Resolving event for my probing path logic to execute and load into the AssemblyLoadContext.Default. That does not seem to be called (checked with breakpoint), however somehow the assembly in question is loaded.

There is a a common managed plugin interface that is located in a separate assembly: Jacobi.Vst.Core. The mixed C++/CLI assembly depends on it as well as the managed plugin we're trying to load.

I am experiencing the problem that my IPlugin (not the actual name) implemented by the plugin is 'not the same type' as the one the mixed C++/CLI assembly has, because that Jacobi.Vst.Core assembly was loaded into an 'IsolatedComponentLoadContext' while I load the plugin -and its Jacobi.Vst.Core dependency?- into AssemblyLoadContext.Default.

So my question is: Is my Resolving event handler not called because that is only used when netcore can't resolve it?
Would it be possible to load >everything< into a dedicated AssemblyLoadContext?

The mixed C++/CLI assembly already marshals calls between a 3rd party native host and the managed plugin, so I want to keep away from marshaling between AssemblyLoadContext's as well. It's a realtime audio application and performance is 'tight' as it is.

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added area-AssemblyLoader-coreclr untriaged New issue has not been triaged by the area owner labels Feb 26, 2020
@obiwanjacobi obiwanjacobi changed the title Direct assemblies away from IsolatedComponentLoadContext towards AssemblyLoadContext.Default Direct assemblies away from IsolatedComponentLoadContext towards a single AssemblyLoadContext Feb 26, 2020
@obiwanjacobi
Copy link
Author

I am a bit embarrassed to have posted the question.
I was stuck in thinking that everything had to go into AssemblyLoadContext.Default but that is not the case - its not even the best solution for my scenario. Once I let go of that I realized that I could simply load the managed plugin assembly into the same AssemblyLoadContext the code was executing from.

I hope this may benifit someone in the future.

class MyAssemblyLoader
{
    public Assembly LoadAssembly(string filePath)
    {
        var loadContext = AssemblyLoadContext.GetLoadContext(typeof(MyAssemblyLoader).Assembly);
        return loadContext.LoadFromAssemblyPath(filePath);
    }
}

@ghost ghost locked as resolved and limited conversation to collaborators Dec 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-AssemblyLoader-coreclr untriaged New issue has not been triaged by the area owner
Projects
None yet
Development

No branches or pull requests

2 participants