簡體   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