C# 无法按程序集加载强名称程序集。LoadFrom(),调用失败,返回0x80004005(E_FAIL)
我有一个Adobe acrobat插件,它在AssemblyResolve事件中使用System.Reflection.Assembly.LoadFile(路径),每当我尝试加载已签名的程序集时,该事件都会失败。错误是C# 无法按程序集加载强名称程序集。LoadFrom(),调用失败,返回0x80004005(E_FAIL),c#,.net,c++-cli,fileloadexception,C#,.net,C++ Cli,Fileloadexception,我有一个Adobe acrobat插件,它在AssemblyResolve事件中使用System.Reflection.Assembly.LoadFile(路径),每当我尝试加载已签名的程序集时,该事件都会失败。错误是 The assembly with display name 'Microsoft.AspNet.SignalR.Client' failed to load in the 'Load' binding context of the AppDomain with ID 1. Th
The assembly with display name 'Microsoft.AspNet.SignalR.Client' failed to load in the 'Load' binding context of the AppDomain with ID 1. The cause of the failure was: System.IO.FileLoadException: Could not load file or assembly 'Microsoft.AspNet.SignalR.Client, Version=2.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))
我必须使用AssemblyResolve事件,因为所需的程序集将位于Acrobat的exe下几层的文件夹中。下面是AssebMyResolve调用的代码
Assembly^ TeamMateIntegrationManagedWrapper::ResolveAssembly(Object^ sender, ResolveEventArgs^ args){
try
{
// This method will be called if an assembly cannot be found.
// The assembly should be 2 folders below the current working directory where the Adobe Acrobat executable lives.
AppDomain^ appDomain = static_cast<AppDomain^>(sender);
String^ path = appDomain->BaseDirectory;
path += "plug_ins\\MyAppName\\" + args->Name->Split(',')[0] + ".dll";
return System::Reflection::Assembly::LoadFile(path);
}
catch (Exception^ ex)
{
String^ msg = ex->Message;
}
return nullptr;}
Assembly^团队集成ManagedRapper::ResolveAssembly(对象^sender,ResolveEventArgs^args){
尝试
{
//如果找不到程序集,将调用此方法。
//程序集应位于Adobe Acrobat可执行文件所在的当前工作目录下的2个文件夹中。
AppDomain ^AppDomain=静态\u转换(发送方);
字符串^path=appDomain->BaseDirectory;
path++=“插件\\MyAppName\\”+args->Name->Split(',')[0]+.dll”;
返回系统::反射::程序集::加载文件(路径);
}
捕获(异常^ex)
{
字符串^msg=ex->Message;
}
返回null ptr;}
Acrobat插件主要使用C语言,但有一个CLI桥接类来包装使用Signal的托管C#程序集
我试过的东西
- 将所有必要的dll与Acrobat的可执行文件放在同一个文件夹中,以便使用AssemblyResolve事件四处走动
- 已验证我在AssemblyResolve事件中提供的dll的信号器版本和PublicKeyToken与ResolveEventArgs中请求的完全匹配
- 已验证我的所有程序集(包括插件dll)都是针对.Net Framework v4.6的,插件dll是为x86生成的,其他程序集是为任何CPU生成的
- 尝试了Assembly::LoadFrom(路径)而不是LoadFile(路径),加载程序集时出现相同错误
- 从源代码重新生成信号器并删除强名称,即在AssebMyResolve事件中成功加载信号器程序集。将强名称添加回信号器程序集,并再次获得上述错误
- 向我的C#程序集添加了强名称,得到了与上面相同的错误,就像信号程序集一样
- 查看了fusion日志查看器,但没有为Acrobat记录任何内容