[英]Mixed assembly won't load from ILMerge-ed result
I have a simple program that references The open-source AlphaVSS library .我有一个引用开源 AlphaVSS 库的简单程序。 It contains 3 dlls:
它包含 3 个 dll:
Now I want to merge my main.exe
with AlphaFS.dll
and AlphaVSS.Common.dll
, leave only AlphaVSS.x64.dll
on the disk.现在我想将我的
main.exe
与AlphaFS.dll
和AlphaVSS.Common.dll
合并,只在磁盘上留下AlphaVSS.x64.dll
。
So I added an AssemblyResolve event to load AlphaVSS.x64.dll from system32:所以我添加了一个 AssemblyResolve 事件来从 system32 加载 AlphaVSS.x64.dll:
AppDomain.CurrentDomain.AssemblyResolve += (sender, args2) =>
{
Console.WriteLine("Loading " + args2.Name);
string name = args2.Name.Split(',')[0];
string path = "c:\\windows\\system32\\" + name + ".dll";
if (args2.Name.StartsWith("AlphaVSS"))
{
if (File.Exists(path))
{
return Assembly.LoadFrom(path);
}
}
return null;
};
And I merged the rest successfully:我成功合并了其余部分:
%ILMerge% /v4 /ndebug /out:"$(TargetDir)all-in-one.exe" "$(TargetDir)$(TargetFileName)" "$(TargetDir)AlphaVSS.Common.dll" "$(TargetDir)AlphaFS.dll"
Then I copied only all-in-one.exe and AlphaVSS.x64.dll
to another computer, and launched all-in-one.exe.然后我只将
all-in-one.exe and AlphaVSS.x64.dll
到另一台计算机,并启动all-in-one.exe。 The first DLL to load is AlphaVSS.x64.dll
and it's loaded.要加载的第一个 DLL 是
AlphaVSS.x64.dll
,它已加载。 Then it tried to load AlphaVSS.Common.dll
and it's not found.然后它尝试加载
AlphaVSS.Common.dll
,但没有找到。
From ILSpy, The AlphaVSS.Common.dll
is already merged into the all-in-one.exe
and loaded.从ILSpy,
AlphaVSS.Common.dll
已经合并到all-in-one.exe
并加载。 But the mixed assembly AlphaVSS.x64.dll
is still referencing AlphaVSS.Common.dll
, so it tried to load it again.但是混合程序集
AlphaVSS.x64.dll
仍在引用AlphaVSS.Common.dll
,因此它尝试再次加载它。
Does anyone know how to resolve this?有谁知道如何解决这个问题?
Based on your answers in comments, when you load AlphaVSS.x64.dll
from the drive, it tries to load AlphaVSS.Common.dll
(since it references it).根据您在评论中的回答,当您从驱动器加载
AlphaVSS.x64.dll
时,它会尝试加载AlphaVSS.Common.dll
(因为它引用了它)。
But you already catching it with your custom resolver.但是您已经使用自定义解析器捕获了它。 And since
AlphaVSS.Common.dll
contains AlphaVSS
this condition will be true if (args2.Name.StartsWith("AlphaVSS"))
and your resolver'll try to load AlphaVSS.Common.dll
from the drive.由于
AlphaVSS.Common.dll
包含AlphaVSS
if (args2.Name.StartsWith("AlphaVSS"))
并且您的解析器将尝试从驱动器加载AlphaVSS.Common.dll
,则此条件为真。
What you need to do is modify your resolver to load only AlphaVSS.x64.dll
from the drive and load AlphaVSS.Common.dll
from contents of current assembly.你需要做的是改变你的解析器仅加载
AlphaVSS.x64.dll
从驱动器和负载AlphaVSS.Common.dll
从当前装配的内容。
In case of AlphaVSS.Common.dll
try doing something like this:如果是
AlphaVSS.Common.dll
尝试执行以下操作:
Assembly assembly = AppDomain.CurrentDomain.GetAssemblies()
.Where(a => a.GetName().Name == "AlphaVSS.Common")
.Single();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.