Cache assembly fetches/resolution so that repeat errors aren't clogging the log
This commit is contained in:
parent
b979b6ddad
commit
d1bb921346
@ -121,12 +121,30 @@ namespace LibationFileManager
|
||||
}
|
||||
*/
|
||||
|
||||
private static Dictionary<string, Assembly> lowEffortCache { get; } = new();
|
||||
private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
|
||||
{
|
||||
// e.g. "System.Windows.Forms, Version=6.0.2.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
|
||||
var asmName = args.Name.Split(',')[0] + ".dll";
|
||||
var here = Path.GetDirectoryName(Environment.ProcessPath);
|
||||
|
||||
var key = $"{asmName}|{here}";
|
||||
|
||||
if (lowEffortCache.TryGetValue(key, out var value))
|
||||
return value;
|
||||
|
||||
var assembly = CurrentDomain_AssemblyResolve_internal(asmName: asmName, here: here);
|
||||
lowEffortCache[key] = assembly;
|
||||
|
||||
//Let the runtime handle any dll not found exceptions.
|
||||
if (assembly is null)
|
||||
Serilog.Log.Logger.Error($"Unable to load module {args.Name}");
|
||||
|
||||
return assembly;
|
||||
}
|
||||
|
||||
private static Assembly CurrentDomain_AssemblyResolve_internal(string asmName, string here)
|
||||
{
|
||||
/*
|
||||
* Commented code used to locate assemblies from the *ConfigApp.exe's module list.
|
||||
* Use this method to locate dependencies when they are not in Libation's program files directory.
|
||||
@ -135,20 +153,15 @@ namespace LibationFileManager
|
||||
var modulePath = ModuleList.SingleOrDefault(m => m.ModuleName.EqualsInsensitive(asmName))?.FileName;
|
||||
#else
|
||||
*/
|
||||
var here = Path.GetDirectoryName(Environment.ProcessPath);
|
||||
|
||||
// find the requested assembly in the program files directory
|
||||
var modulePath =
|
||||
Directory.EnumerateFiles(here, asmName, SearchOption.TopDirectoryOnly)
|
||||
.SingleOrDefault();
|
||||
|
||||
//#endif
|
||||
//#endif
|
||||
if (modulePath is null)
|
||||
{
|
||||
//Let the runtime handle any dll not found exceptions.
|
||||
Serilog.Log.Logger.Error($"Unable to load module {args.Name}");
|
||||
return null;
|
||||
}
|
||||
|
||||
return Assembly.LoadFrom(modulePath);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user