Skip to content

How to handle assemblies that fail to resolve now there is no DomainContext.AssemblyResolve event? #290

@patricknolan

Description

@patricknolan

Hi,

In the full .NET Framework I can subscribe to the AppDomain.AssemblyResolve event and handle the discovery of assemblies that have failed to load.

If .NET Core fails to find an assembly how can this be handled? There's a Resolving event available via AssemblyLoadContext.Default but this isn't really what I'm after. I thought the following code might do the the job but of course "var assembly = assemblyLoadContext.LoadFromAssemblyName(assemblyName);" results in a cyclic loop.

Could you please advise how this can now be achieved?

AssemblyLoadContext.Default.Resolving += this.OnAssemblyResolve;

protected virtual Assembly OnAssemblyResolve(AssemblyLoadContext assemblyLoadContext, AssemblyName assemblyName)
{
    var assembly = assemblyLoadContext.LoadFromAssemblyName(assemblyName);
    if (assembly == null)
    {
        assembly = this.HandleDiscovery(assemblyName);
    }
    return assembly;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions