如果加载不到外部库,可以先将dll加载一遍,就不会处DLL的异常问题
private static void TryLoadAssembly()
{
Assembly entry = Assembly.GetEntryAssembly();
//找到当前执行文件所在路径
string dir = Path.GetDirectoryName(entry.Location);
string entryName = entry.GetName().Name;
//获取执行文件同一目录下的其他dll
foreach (string dll in Directory.GetFiles(dir, "*.dll"))
{
if (entryName.Equals(Path.GetFileNameWithoutExtension(dll))) { continue; }
//非程序集类型的关联load时会报错
try
{
AssemblyLoadContext.Default.LoadFromAssemblyPath(dll);
}
catch (Exception ex)
{
}
}
}
(166条消息) .NET Core项目中引用.net framework封装的dll库_.net core 引用dll_aishuju1的博客-CSDN博客
如果出现 System.BadImageFormatException 问题,是目标平台不一致引起的
(166条消息) C# System.BadImageFormatException 解决方法_boonya的博客-CSDN博客