C# 无法按程序集加载强名称程序集。LoadFrom(),调用失败,返回0x80004005(E_FAIL)

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

我有一个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. 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记录任何内容
  • 创建了一个C++控制台应用程序,该应用程序包含相同的CLI桥包装器类,该类使用与Cyralr相同的C组件,与上面相同的错误。查看了fusion日志,但在我的ConsoleApplication.exe文件夹下没有Microsoft.AspNet.signal.dll的日志。查看了我的C#程序集的fusino日志,该程序集使用SignalR,并且没有任何参考/提及试图在日志文件中加载SignalR dll
Adobe Reader有一个选项/首选项编辑->首选项->安全性(增强)->在启动时启用受保护模式,在受保护的沙箱中启动应用程序。这种保护防止加载强名称dll。

不要盲目地提供加载任何缺少的程序集的功能,首先检查它是否确实存在于插件目录中。并且始终使用LoadFrom,从不使用LoadFile。您必须启动fuslogvw.exe,请确保从提升的命令提示符(以管理员身份运行)启动它。感谢您的建议。在尝试Assembly.LoadFrom(路径)之前,我添加了一个File.Exists(路径)检查。我的开发机器上安装了AcrobatReader和AcrobatPro。我决定卸载Reader并尝试让它与Pro一起工作。使用Pro,强名称dll加载没有问题,创建了融合日志,一切都很好。在第二天左右,我将卸载Pro,并尝试只使用已安装的Reader。当我弄清楚后,我会加上一条评论。谢谢