Handle non-.NET assemblies in dll plugins

Trycatch situations where people put libz3.dll in the plugins folder.
This commit is contained in:
Kurt 2022-06-11 17:06:57 -07:00
parent c66588666c
commit c1eb70f57c

View file

@ -40,10 +40,20 @@ public static class PluginLoader
private static IEnumerable<Assembly> GetAssemblies(IEnumerable<string> dllFileNames, PluginLoadSetting loadSetting) private static IEnumerable<Assembly> GetAssemblies(IEnumerable<string> dllFileNames, PluginLoadSetting loadSetting)
{ {
var loadMethod = GetPluginLoadMethod(loadSetting); var loadMethod = GetPluginLoadMethod(loadSetting);
var assemblies = dllFileNames.Select(loadMethod); foreach (var file in dllFileNames)
{
Assembly x;
try { x = loadMethod(file); }
catch (Exception ex)
{
Debug.WriteLine($"Unable to load plugin from file: {file}");
Debug.WriteLine(ex.Message);
continue;
}
yield return x;
}
if (loadSetting.IsMerged()) if (loadSetting.IsMerged())
assemblies = assemblies.Concat(new[] { Assembly.GetExecutingAssembly() }); // load merged too yield return Assembly.GetExecutingAssembly(); // load merged too
return assemblies;
} }
private static Func<string, Assembly> GetPluginLoadMethod(PluginLoadSetting pls) => pls switch private static Func<string, Assembly> GetPluginLoadMethod(PluginLoadSetting pls) => pls switch