mirror of
https://github.com/ShrlAlgo/AddinManager.git
synced 2026-03-07 16:38:56 +00:00
修复字节流加载找不到路径
This commit is contained in:
@@ -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)
|
||||||
|
|||||||
Reference in New Issue
Block a user