Skip to content

Remove assumption that MSBuild controls AssemblyLoadContext.Default #6794

@rainersigwald

Description

@rainersigwald

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);
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    .NET CoreArea: EngineIssues impacting the core execution of targets and tasks.triaged

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions