2013-07-18 50 views
3

所以,我知道有很多類似的問題,但是我在過去一天中傾注了很多答案,沒有任何幫助。DLL Load上的FileLoadException

我正在開發引用一堆外部DLL的WPF應用程序。特別是有一個DLL稱爲DefinitionInterpreter,它已被證明會造成麻煩。在我參考的每一個項目中,它都是固執的,選擇不工作。我能夠在單元測試套件中使用它,但是,我不能,盡我所能,讓它在我的WPF應用程序中運行。

我已經試過GAC,清理我的項目,添加它並刪除它,重新啓動,檢查版本,檢查依賴項,並且沒有任何工作。

我不斷收到同樣的異常:

無法加載文件或程序集「DefinitionInterpreter,版本= 3.6.0.0,文化=中性公鑰= null或它的一個依賴。定位的程序集清單定義與程序集引用不匹配。 (來自HRESULT的例外:0x80131040)

我試過在ildasm.exe中打開DLL,它沒有顯示任何異常。它只有依賴項是System.Xml,System.Core和mscorlib。

當我檢查清單,它驗證的版本是3.6.0.0

,真正讓我是,它在我的項目之一的事情,但我不能讓它到另一個工作,即使它們引用的是相同的DLL(相同的路徑和所有內容)。

有什麼建議嗎?我正在使用.NET 4.0(它是一個項目要求,它是4.0),並已嘗試x86和x64。

編輯:

觀看融合登錄詳細信息之後,我得到這個作爲輸出:

*** Assembly Binder Log Entry (7/18/2013 @ 7:07:42 PM) *** 

The operation failed. 
Bind result: hr = 0x80131040. No description available. 

Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll 
Running under executable E:\Src\Hermes\Tool\bin\Debug\HermesClient.vshost.exe 
--- A detailed error log follows. 

=== Pre-bind state information === 
LOG: DisplayName = DefinitionInterpreter, Version=3.6.0.0, Culture=neutral, PublicKeyToken=null 
(Fully-specified) 
LOG: Appbase = file:///E:/Src/Hermes/Tool/bin/Debug/ 
LOG: Initial PrivatePath = NULL 
LOG: Dynamic Base = NULL 
LOG: Cache Base = NULL 
LOG: AppName = HermesClient.vshost.exe 
Calling assembly : SomeAssembly, Version=13.5.13.0, Culture=neutral, PublicKeyToken=null. 
=== 
LOG: This bind starts in default load context. 
LOG: Using application configuration file: E:\Src\Hermes\Tool\bin\Debug\HermesClient.vshost.exe.Config 
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config. 
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind). 
LOG: Attempting download of new URL file:///E:/Src/Hermes/Tool/bin/Debug/DefinitionInterpreter.DLL. 
LOG: Assembly download was successful. Attempting setup of file: E:\Src\Hermes\Tool\bin\Debug\DefinitionInterpreter.dll 
LOG: Entering run-from-source setup phase. 
LOG: Assembly Name is: DefinitionInterpreter, Version=3.6.0.0, Culture=neutral, PublicKeyToken=75a99a2a5bcd4c96 
WRN: Comparing the assembly name resulted in the mismatch: PUBLIC KEY TOKEN 
ERR: The assembly reference did not match the assembly definition found. 
ERR: Run-from-source setup phase failed with hr = 0x80131040. 
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated. 

在我的csproj參考如下:

<Reference Include="DefinitionInterpreter, Version=3.6.0.0, Culture=neutral, PublicKeyToken=75a99a2a5bcd4c96, processorArchitecture=MSIL"> 
     <SpecificVersion>False</SpecificVersion> 
     <HintPath>..\..\..\..\DefinitionInterpreter.dll</HintPath> 
     <Private>True</Private> 
    </Reference> 

當我執行命令sn -T DefinitionInterpreter.dll我得到75a99a2a5bcd4c96。我真的很茫然,在運行時它認爲公鑰標記爲空,爲什麼會有不匹配。

+4

使用「Fusion Log Viewer」在兩種情況下查看它的加載位置 - 可能會爲您提供一些有關它發生的原因。對於給定數量的信息,它不太可能得到回答... –

+0

@AlexeiLevenkov在使用Fusion日誌查看器之後,我發現它工作正常,顯然由於未知原因存在公鑰不匹配。 –

+0

日誌與異常消息不匹配,請務必對其進行更新。嘗試通過將此項目複製到您的C:驅動器來刪除至少一種可能的故障模式。 –

回答

2

因此,從日誌看起來像「SomeAssembly」鏈接到該DLL的非簽名版本,但所有本地版本都簽名。

如果您自己構建「SomeAssembly」,請檢查對「DefinitionInterpreter」的引用是否指向簽名版本,否則再次檢查ILDasm中的「SomeAssembly」是否確實引用了未簽名版本並要求所有者提供另一個版本。

+0

這最終被證明是正確的。謝謝阿列克謝。事實證明,我正在使用稍微過時的「SomeAssembly」的錯誤副本。 –

相關問題