修复字节流加载找不到路径

This commit is contained in:
GG Z
2026-01-31 21:24:17 +08:00
parent 8d800e8927
commit c884115bcd

View File

@@ -116,28 +116,14 @@ namespace AddInManager
// 加载复制后的文件 // 加载复制后的文件
return LoadAddin(destPath); return LoadAddin(destPath);
} }
private Assembly LoadAddin(string filePath) private Assembly LoadAddin(string filePath)
{ {
Assembly assembly = null; Assembly assembly = null;
try try
{ {
// 【核心修改】:使用字节流加载,而不是 LoadFile
// 这样可以避免文件锁定,并且每次 Load 都会视为新的程序集实例
if (File.Exists(filePath)) if (File.Exists(filePath))
{ {
byte[] assemblyBytes = File.ReadAllBytes(filePath); assembly = Assembly.LoadFrom(filePath);
byte[] pdbBytes = null;
// 尝试加载 PDB 以支持调试
string pdbPath = Path.ChangeExtension(filePath, "pdb");
if (File.Exists(pdbPath))
{
pdbBytes = File.ReadAllBytes(pdbPath);
}
// 使用 Load(bytes, pdbBytes)
assembly = Assembly.Load(assemblyBytes, pdbBytes);
} }
} }
catch (Exception ex) catch (Exception ex)