-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Description
Motivations
Concrete Type
There is a desire to simplify System.Runtime.Loader.AssemblyLoadContext usage by making it a concrete type. (from #28397)
The existing class is abstract because the Load() method is not implemented. Recommend adding a default implementation of Load() as a method returning null and make the constructors public. This is a logical default implementation as it implies falling back to the AssemblyLoadContext.Default for first chance to load the assembly.
Naming ALCs
To simplify diagnostics for System.Runtime.Loader.AssemblyLoadContext (from #28395):
- Add a
Nameto each ALC making understanding of role of each ALC easier
The name will make it more convenient to understand what is happening in the debugger. It will also make any tracing easier to understand.
- The Default ALC would be constructed with name = "Default".
- The Assembly.LoadFile(path) generated ALCs would be constructed with name = "Assembly.LoadFile(path)" .
- Custom AssemblyLoadContext implementations could provide a logical name.
- The legacy Custom AssemblyLoadContext using the current protected constructor will not set the name. In these cases the name will default to
null.
Set of ALCs & Assemblies
Provide a mechanism to iterate through ALCs and their contents to create a graphical representation. These APIs are intended to help make understanding and diagnosing isolation designs (from #28395).
Add Contexts, and Assemblies properties.
Proposed API changes
namespace System.Runtime.Loader
{
public partial class AssemblyLoadContext
{
// Add a public constructor
// Allow naming each AssemblyLoadContext
public AssemblyLoadContext(String name, bool isCollectible = false);
// Add default Load() implementation
protected virtual System.Reflection.Assembly Load(System.Reflection.AssemblyName assemblyName)
{
return null;
}
public String Name { get; }
// Override the ToString to return Name, type name, and unique instance id.
public override string ToString();
// Set of ALCs
public static IEnumerable<AssemblyLoadContext> Contexts { get; }
// Set of Assemblies in the ALC
public IEnumerable<System.Reflection.Assembly> Assemblies { get; }
}
}Open issues
- Consider renaming
ContextstoAllContextsorGetAllContexts