How to handle assemblies that fail to resolve on load?



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;


I don’t know man!
But here:

I have some (multi platform / target, including .NET core) code that fiddle with assembly load. Perhaps you can find some inspiration there?

.NET Foundation Website | Blog | Projects | Code of Conduct