C# DLL加载时出现FileLoadException

C# DLL加载时出现FileLoadException,c#,.net,dll,fileloadexception,C#,.net,Dll,Fileloadexception,所以,我知道有很多类似的问题,但在过去的一天里,我已经给出了很多答案,没有任何帮助 我正在开发一个WPF应用程序,它引用了一堆外部DLL。特别是有一个DLL,叫做Definition解释器,它已经被证明会引起麻烦。在我提到的每一个项目中,它都很固执,选择不工作。我能够让它在我的单元测试套件中工作,但是,我不能,尽管我可能会尝试,让它在我的WPF应用程序中工作 我尝试过GAC,清理我的项目,添加和删除它,重新启动,检查版本,检查依赖项,但什么都不起作用 我总是得到同样的例外: 无法加载文件或程序集

所以,我知道有很多类似的问题,但在过去的一天里,我已经给出了很多答案,没有任何帮助

我正在开发一个WPF应用程序,它引用了一堆外部DLL。特别是有一个DLL,叫做Definition解释器,它已经被证明会引起麻烦。在我提到的每一个项目中,它都很固执,选择不工作。我能够让它在我的单元测试套件中工作,但是,我不能,尽管我可能会尝试,让它在我的WPF应用程序中工作

我尝试过GAC,清理我的项目,添加和删除它,重新启动,检查版本,检查依赖项,但什么都不起作用

我总是得到同样的例外:

无法加载文件或程序集“Definition解释器,版本=3.6.0.0,区域性=中性,PublicKeyToken=null”或其依赖项之一。定位的程序集清单定义与程序集引用不匹配。(来自HRESULT的异常:0x8013100)

我尝试在ildasm.exe中打开DLL,它没有显示任何异常。它唯一的依赖项是System.Xml、System.Core和mscorlib

当我检查清单时,它会验证版本是否为3.6.0.0

真正让我感兴趣的是,它在我的一个项目中工作,但我无法在另一个项目中工作,即使它们引用相同的DLL(相同的路径和所有内容)

有什么建议吗?我正在使用.NET4.0(项目要求它是4.0),并且已经尝试了x86和x64

编辑:

查看Fusion日志详细信息后,我将此作为输出:

*** 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>

假的
..\..\..\..\definition解释器.dll
真的

当我执行命令sn-T DefinitionInterpreter.dll时,我得到了75a99a2a5bcd4c96。老实说,我不知道它在运行时如何认为公钥令牌为空,以及为什么存在不匹配。

因此,从日志中看,“SomeAssembly”似乎链接到该DLL的非签名版本,但所有本地版本都已签名


如果您自己构建“SomeAssembly”,请检查对“Definition解释器”的引用是否指向签名版本,否则请与ILDasm再次检查“SomeAssembly”是否确实指向未签名版本,并要求所有者提供另一个版本

使用“Fusion Log Viewer”查看这两种情况下的加载位置-可能会让您了解为什么会发生这种情况。在给定的信息量下,它不太可能被回答…@AlexeiLevenkov在玩了Fusion log viewer之后,我让它工作了,显然有一个公钥不匹配,原因不明。日志与异常消息不匹配,请务必更新它。通过将此项目复制到您的C:驱动器,尝试至少删除一种可能的故障模式。@HansPassant我向您保证,当我通过Fusion获得该日志时,我也遇到了同样的异常。我会试着把它移到C盘上,结果是正确的。谢谢阿列克谢。原来我用的是“SomeAssembly”的错误副本,有点过时了。