繁体   English   中英

无法通过Assembly.LoadFrom()加载强名称程序集,调用失败,并显示0x80004005(E_FAIL)

[英]Cannot load a Strong name assembly by Assembly.LoadFrom(), call fails with 0x80004005 (E_FAIL)

我有一个Adobe acrobat插件,在AssemblyResolve事件中使用System.Reflection.Assembly.LoadFile(path),该事件在我尝试加载签名的程序集时都会失败。 错误是

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下面几级的文件夹中。 这是AssebmlyResolve调用的代码。

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;}

Acrobat插件主要使用C语言编写,但是具有CLI桥接类来包装使用SignalR的托管C#程序集。

我尝试过的事情。

  • 将所有必需的dll与Acrobat可执行文件放在同一文件夹中,以使用AssemblyResolve事件解决该问题。
  • 验证了我在AssemblyResolve事件中提供的dll的SignalR版本和PublicKeyToken与ResolveEventArgs中要求的完全匹配
  • 验证我的所有程序集(包括插件dll)都针对.Net Framework v4.6,并且插件dll是针对x86构建的,而其他程序集针对Any CPU进行的。
  • 尝试了Assembly :: LoadFrom(path)而不是LoadFile(path),相同的错误加载程序集。
  • 从源代码重建SignalR并删除“强名称”,即在AssebmlyResolve事件中成功加载的SignalR程序集。 将强名重新添加回SignalR程序集,并再次出现上述错误。
  • 为我的C#程序集添加了Strong名称,与SignalR程序集一样,出现了与上述相同的错误。
  • 查看了融合日志查看器,但没有为Acrobat记录任何内容。
  • 创建了一个C ++控制台应用程序,其中包含相同的CLI桥接包装器类,该类使用消耗SignalR的相同C#程序集,并且存在与上述相同的错误。 在我的ConsoleApplication.exe文件夹下查看了融合日志,但没有Microsoft.AspNet.SignalR.dll的日志。 在fusino日志中查看了使用SignalR的C#程序集的fusino日志,没有任何试图加载到日志文件中的SignalR dll的引用/提及。

Adobe Reader在启动时具有选项/首选项Edit-> Preferences->安全性(增强)->启用保护模式,可在受保护的沙箱中启动应用程序。 此保护可防止加载名为Strong的dll。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM