Skip to content

Make AssemblyLoadContext a concrete type #28397

Closed

Description

@sdmaclea

There is a desire to simplify System.Runtime.Loader.AssemblyLoadContext usage by making it a concrete type.

The existing class is abstract because the Load() method is not implemented.

The simplest solution is to simply implement Load() as a method returning null and make the appropriate constructors public.

Activity

  1. self-assigned this
    on Jan 10, 2019
  2. sdmaclea commented on Jan 10, 2019

    @sdmaclea
    ContributorAuthor

    A more controversial and/or complete solution could be to extend #27787. Something like

    public interface IDependencyResolver
    {
        public string ResolveAssemblyToPath(AssemblyName assemblyName);
        public string ResolveUnmanagedDllToPath(string unmanagedDllName);
    }
    
    public class AssemblyDependencyResolver : IDependencyResolver
    {
    }
    
    public class AssemblyLoadContext
    {
        public AssemblyLoadContext(IDependencyResolver earlyDependencyResolver);
    
        protected virtual System.Reflection.Assembly Load (System.Reflection.AssemblyName assemblyName)
        {
            if (earlyResolver)
            {
                String path = earlyResolver.ResolveAssemblyToPath(assemblyName);
                if (!path.Empty())
                {
                    return LoadFromAssemblyPath(path);
                }
            }
            return null;
        }
        protected virtual IntPtr LoadUnmanagedDll (string unmanagedDllName)
        {
             // Similar implementation
        }
    }
  3. sdmaclea commented on Jan 10, 2019

    @sdmaclea
    ContributorAuthor
  4. jkotas commented on Jan 11, 2019

    @jkotas
    Member

    Both parts look reasonable to me.

  5. vitek-karas commented on Jan 22, 2019

    @vitek-karas
    Member

    I think we should do the simple Load returning null.

    The second proposal with dependency resolver ventures into the area we've already been, which is trying to come up with a simple solution for "plugin" loads. With the proposed API it would be very simple (2 lines?) to create an ALC to load plugins into, which would dictate a policy decision - which is the problematic part. The above implementation is the "full isolation" policy, which might work for very clear plugin models, but it doesn't work out of the box as it requires for the shared types/assemblies to not be included in the plugin.

    I would rather we first make the class non-abstract in the simple manner without additional logic. And try to tackle the "easy to use" APIs later on.
    If we decide that we also want the dependency resolver based implementation it can be added later on with relative ease.

  6. swaroop-sridhar commented on Jan 22, 2019

    @swaroop-sridhar
    Contributor

    I agree with @vitek-karas. The simple implementation of Load() is sufficient for cases where:

    • We only use ALCs for isolation, with current default Load() semantics
    • We only alter assembly/unmanaged-library load semantics using events

    without creating unnecessary inheritance as in here.

    It is reasonable to ALC to be inherited when there is change in assembly-load behavior.
    In the way, the second Load() implementation only moves the inheritence hierarchy from ALCs to IDependencyResolver implementations.

  7. sdmaclea commented on Jan 23, 2019

    @sdmaclea
    ContributorAuthor

    Moved to dotnet/corefx#34791

  8. transferred this issue fromdotnet/corefxon Feb 1, 2020
  9. added this to the 3.0 milestone on Feb 1, 2020
  10. ghost locked as resolved and limited conversation to collaborators on Dec 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

api-needs-workarea-System.Runtime

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions