【问题标题】:FileLoadException on DLL LoadDLL 加载时的 FileLoadException
【发布时间】:2013-07-18 22:23:18
【问题描述】:

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

我正在开发一个引用大量外部 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(项目要求它是 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。老实说,我不知道它在运行时如何认为公钥令牌为空以及为什么不匹配。

【问题讨论】:

  • 在这两种情况下使用“Fusion Log Viewer”查看它的加载位置 - 可能会给您一些关于它发生原因的想法。有了给定数量的信息,它不太可能得到回答......
  • @AlexeiLevenkov 在玩过 Fusion 日志查看器后,我开始使用它,但显然公钥不匹配,原因不明。
  • 日志与异常信息不符,请务必更新。尝试通过将此项目复制到您的 C: 驱动器来删除至少一种可能的故障模式。
  • @HansPassant 我向你保证,当我通过 Fusion 获取该日志时,我遇到了同样的异常。不过我会尝试将其移至 C 盘。

标签: c# .net dll fileloadexception


【解决方案1】:

因此,从日志看来,“SomeAssembly”链接到该 DLL 的未签名版本,但所有本地版本都已签名。

如果您自己构建“SomeAssembly” - 检查对“DefinitionInterpreter”的引用是否指向签名版本,否则请与 ILDasm 仔细检查“SomeAssembly”确实是指非签名版本并要求所有者提供另一个版本。

【讨论】:

  • 这最终是正确的。谢谢阿列克谢。事实证明我使用了错误的“SomeAssembly”副本,它有点过时了。
猜你喜欢
  • 1970-01-01
  • 2014-02-23
  • 2023-04-06
  • 1970-01-01
  • 2010-09-16
  • 2018-04-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多