Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

How to handle assemblies that fail to resolve on load?

$
0
0

Hi,

In the full .NET Framework I cam 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.

Does anyone have any ideas?

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



Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>