private Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
// This line causes a StackOverflowException unless Resources has already been called upon previously
this.logger.LogDebug(Resources.Resolver_ResolvingAssembly, args.Name, args?.RequestingAssembly?.FullName ?? Resources.Resolver_UnspecifiedRequestingAssembly);
Assembly asm;
// The supplied assembly name could be a file name or an assembly full name. Work out which it is
bool isFileName = Utilities.IsAssemblyLibraryFileName(args.Name);
// Now work out the file name we are looking for
string fileName = GetAssemblyFileName(args.Name);
foreach (string rootSearchPath in rootSearchPaths)
{
foreach (string file in Directory.GetFiles(rootSearchPath, fileName, SearchOption.AllDirectories))
{
asm = Assembly.LoadFile(file);
if (
// If the input was e.g foo.dll then compare against the file name...
(isFileName && string.Equals(Path.GetFileName(asm.Location), fileName, StringComparison.OrdinalIgnoreCase))
||
// ... otherwise compare against the full name
(!isFileName && string.Equals(args.Name, asm.FullName, StringComparison.OrdinalIgnoreCase))
)
{
this.logger.LogDebug(Resources.Resolver_AssemblyLocated, file);
return asm;
}
else
{
this.logger.LogDebug(Resources.Resolver_RejectedAssembly, asm.FullName);
}
}
}
this.logger.LogDebug(Resources.Resolver_FailedToResolveAssembly);
return null;
}