DLL加载时的FileLoadException

3
所以,我知道有很多类似的问题,但是在过去的一天里,我浏览了许多答案,但没有任何帮助。
我正在开发一个引用了许多外部DLL的WPF应用程序。有一个特定的DLL,称为DefinitionInterpreter,已经证明会导致麻烦。在我引用它的每个项目中,它都很顽固,并选择不工作。我能够让它在我的单元测试套件中工作,但是,无论如何尝试,我都无法让它在我的WPF应用程序中工作。
我尝试了GAC、清理项目、添加和删除它、重新启动、检查版本、检查依赖项等等,但都没有起作用。
我一直收到同样的异常:
“无法加载文件或程序集“DefinitionInterpreter,Version=3.6.0.0,Culture=neutral,PublicKeyToken=null”或其某个依赖项。所定位的程序集清单定义与程序集引用不匹配。(HRESULT的异常:0x80131040)”
我尝试用ildasm.exe打开DLL,但没有显示任何异常。它的唯一依赖关系是System.Xml、System.Core和mscorlib。
当我检查清单时,它验证版本为3.6.0.0
真正让我困扰的是,它在我的一个项目中可以工作,但是我无法让它在另一个项目中工作,尽管它们引用了相同的DLL(路径和一切都相同)。
有什么建议吗?我正在使用.NET 4.0(这是一个项目要求),并尝试了x86和x64。
编辑:
查看Fusion Log详细信息后,我得到以下输出:
*** 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”查看两种情况下它从哪里加载-这可能会给您一些关于为什么会发生这种情况的想法。在没有足够信息的情况下,很难回答这个问题... - Alexei Levenkov
@AlexeiLevenkov 在使用 Fusion 日志查看器进行尝试后,我终于让它正常工作了。但是出现了公钥不匹配的问题,原因未知。 - Phillip Huff
日志与异常信息不匹配,请确保更新日志。尝试通过将此项目复制到 C: 驱动器中,删除至少一种可能的故障模式。 - Hans Passant
@HansPassant 我向您保证,当我通过Fusion获取该日志时,我也遇到了相同的异常。不过我会尝试将其移动到C盘。 - Phillip Huff
1个回答

2

从日志中看,似乎"SomeAssembly"链接到了那个DLL的非签名版本,但所有本地版本都已经签名。

如果你自己构建了"SomeAssembly" - 请检查是否引用了签名版本的"DefinitionInterpreter",否则请使用 ILDasm 再次确认"SomeAssembly"确实引用了非签名版本,并要求作者提供另一个版本。


这最终被证明是完全正确的。谢谢Alexei。事实证明我使用了一个略微过时的“SomeAssembly”的错误副本。 - Phillip Huff

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接