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

Remove assumption that MSBuild controls AssemblyLoadContext.Default #6794

Open
rainersigwald opened this issue Aug 30, 2021 · 1 comment · May be fixed by #11111
Open

Remove assumption that MSBuild controls AssemblyLoadContext.Default #6794

rainersigwald opened this issue Aug 30, 2021 · 1 comment · May be fixed by #11111
Labels
Area: Engine Issues impacting the core execution of targets and tasks. .NET Core triaged

Comments

@rainersigwald
Copy link
Member

MSBuild has several explicit references to AssemblyLoadContext.Default. That prevents an application from using the MSBuild API in a disposable (or otherwise managed) context.

return AssemblyLoadContext.Default.LoadFromAssemblyPath(_taskAssemblyFile);

if (FileSystems.Default.FileExists(assemblyNameInExecutableDirectory))
{
return AssemblyLoadContext.Default.LoadFromAssemblyPath(assemblyNameInExecutableDirectory);
}

This one is potentially OK since it's only to support an escape-hatch feature, but we can also consider removing it:

private Assembly LoadUsingLegacyDefaultContext(string fullPath)
{
lock (_guard)
{
if (!_resolvingHandlerHookedUp)
{
AssemblyLoadContext.Default.Resolving += TryResolveAssembly;
_resolvingHandlerHookedUp = true;
}
Assembly assembly;
if (_pathsToAssemblies.TryGetValue(fullPath, out assembly))
{
return assembly;
}
return LoadAndCache(AssemblyLoadContext.Default, fullPath);
}
}

@jzabroski
Copy link

@rainersigwald What would you like to see as the solution here? Maybe I can contribute a PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Engine Issues impacting the core execution of targets and tasks. .NET Core triaged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants