【问题标题】:Could not load file or assembly or one of its dependencies. The located assembly's manifest definition does not match the assembly reference无法加载文件或程序集或其依赖项之一。找到的程序集的清单定义与程序集引用不匹配
【发布时间】:2017-11-24 11:17:49
【问题描述】:

我知道关于这个问题有几个类似的主题(相信我,我花了过去两天阅读所有这些主题),但在我奇怪的情况下它们都没有帮助。
所以我来到这里,也许有人可以告诉我可能是什么问题。

我们有一个 C# (WPF) 控件 TreeListView 的源代码。
它使用 VS2015 开发命令提示符使用 csc.exe(较大项目的一部分,IDE 不用于编译)和以下参数进行编译:

/reference:"System.Xaml.dll" 
/reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\PresentationCore.dll" 
/reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\WindowsBase.dll" 
/reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\WindowsFormsIntegration.dll" 
/reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\PresentationFramework.dll" 
/nowarn:1701,1702 /errorreport:prompt /warn:4 /platform:x86 /define:DEBUG;TRACE /debug+ /debug:full /optimize- /target:library  /out:..\debug\TreeListView.dll  

...here all the .cs source files are listed...

/resource:"..\TreeListView\obj\debug\TreeListView.g.resources" 

我们所有的 C#/WPF DLL 都在命令行中使用相同的选项进行编译。

它编译得很好,我有 TreeListView.dll。它不是强命名的。
它被复制到 mainApp.exe 旁边,当我运行主应用程序并尝试使用带有此 TreeListView 的窗口时,出现异常

*** Exception ***: System.IO.FileLoadException
Message: Could not load file or assembly 'TreeListView, PublicKeyToken=ffedd4b1334b06f5' or one of its dependencies. 
The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Source: mscorlib

main_app 也是用 csc.exe 编译的,正好引用上面编译的 TreeListView.dll 的输出

顺便说一句,不知道为什么它显示公钥,当它不是强命名时

sn -T debug\TreeListView.dll

Microsoft (R) .NET Framework Strong Name Utility  Version 4.0.30319.0
Copyright (c) Microsoft Corporation.  All rights reserved.

debug\TreeListView.dll does not represent a strongly named assembly

其他观察

在 VS2015 IDE 中,我创建了一个新的 WPF 应用程序,并引用了上面编译的 TreeListView.dll - 并在 XAML 中使用了该控件:它立即在 GUI XAML 设计器中显示Could not load file or assembly 'TreeListView, PublicKeyToken=ffedd4b1334b06f5' or one of its dependencies. The system cannot find the file specified.
(注意,这里的错误是The system cannot find the file specified.

我认为 IDE 会提供更多信息,但这里没有新内容。

其他信息: 整个构建/运行过程在 VS2008 (.NET3.5) 上运行良好,现在在迁移到 VS2015 (.NET4) 之后,更新体验,并且仅使用这个 TreeControl.dll

我检查了该 dll 的所有引用、使用的框架、ILSpy、ildasm、ProcessMonitor for file not found 等,但找不到任何有用的东西。

ildasm > TreeControl.dll 的清单 - 这对我来说也不错

// Metadata version: v4.0.30319
.assembly extern mscorlib
{
  .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )                         // .z\V.4..
  .ver 4:0:0:0
}
.assembly extern PresentationFramework
{
  .publickeytoken = (31 BF 38 56 AD 36 4E 35 )                         // 1.8V.6N5
  .ver 4:0:0:0
}
.assembly extern System.Xaml
{
  .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )                         // .z\V.4..
  .ver 4:0:0:0
}
.assembly extern WindowsBase
{
  .publickeytoken = (31 BF 38 56 AD 36 4E 35 )                         // 1.8V.6N5
  .ver 4:0:0:0
}
.assembly extern PresentationCore
{
  .publickeytoken = (31 BF 38 56 AD 36 4E 35 )                         // 1.8V.6N5
  .ver 4:0:0:0
}
.assembly extern System
{
  .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )                         // .z\V.4..
  .ver 4:0:0:0
}
.assembly extern System.Core
{
  .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )                         // .z\V.4..
  .ver 4:0:0:0
}

如果您知道要检查什么,我们将不胜感激。

【问题讨论】:

    标签: c# .net wpf dependencies .net-assembly


    【解决方案1】:

    尝试使用 Fuslogvw 在运行时绑定失败。在您运行应用程序时,将设置设置为“记录绑定失败到磁盘”。

    任何失败的绑定都会记录在窗口中。您可以双击日志以获取有关哪个 dll 尝试加载 TreeListView 程序集以及它尝试查找该 dll 的所有位置的完整详细信息。

    【讨论】:

    • 非常感谢!这个工具帮助了我,错误是:WRN: Comparing the assembly name resulted in the mismatch: PUBLIC KEY TOKEN 当二进制文件没有强命名时,异常包含:“PublicKeyToken=ffedd4b1334b06f5”对我来说已经很奇怪了,见上文。但是,二进制文件中的文本搜索显示它包含“PublicKeyToken=ffedd4b1334b06f5”。我发现在 csc.exe 编译期间使用的二进制文件(TreeListView.g.resources-此二进制文件由 IDE 生成)包含此密钥。
    • ...继续... 在 IDE 中,加载 TreeListView 项目,然后取消选中“签名程序集”,并重建以重新生成 TreeListView.g.resources。这不包含任何公钥,通过文件搜索检查。然后用 csc.exe 重新编译 TreeListView.dll(现在使用新的 TreeListView.g.resources),它可以工作了!所以简而言之,当 TreeListView.g.resources 生成时,它带有选项“签名程序集”,但最终的 TreeListView.dll 没有强命名,但仍然部分以某种方式签名,但“不可见” - 但是导致异常。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-01-21
    • 2019-12-04
    • 2021-10-15
    • 1970-01-01
    • 2013-08-24
    • 1970-01-01
    • 2015-10-30
    相关资源
    最近更新 更多