C# 定位的程序集的清单定义与程序集引用不匹配

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/215026/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 18:26:39  来源:igfitidea点击:

The located assembly's manifest definition does not match the assembly reference

c#referencecompiler-errorsdependenciesversion

提问by leora

I am trying to run some unit tests in a C# Windows Forms application (Visual Studio 2005), and I get the following error:

我正在尝试在 C# Windows 窗体应用程序 (Visual Studio 2005) 中运行一些单元测试,但出现以下错误:

System.IO.FileLoadException: Could not load file or assembly 'Utility, Version=1.2.0.200, Culture=neutral, PublicKeyToken=764d581291d764f7' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)**

at x.Foo.FooGO()

at x.Foo.Foo2(String groupName_) in Foo.cs:line 123

at x.Foo.UnitTests.FooTests.TestFoo() in FooTests.cs:line 98**

System.IO.FileLoadException: Could not load file or assembly 'Utility, Version=1.2.0.203, Culture=neutral, PublicKeyToken=764d581291d764f7' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

System.IO.FileLoadException:无法加载文件或程序集“Utility,Version=1.2.0.200,Culture=neutral,PublicKeyToken=764d581291d764f7”或其依赖项之一。定位的程序集的清单定义与程序集引用不匹配。(来自 HRESULT 的异常:0x80131040)**

在 x.Foo.FooGO()

在 Foo.cs:line 123 中的 x.Foo.Foo2(String groupName_)

在 FooTests.cs:line 98** 中的 x.Foo.UnitTests.FooTests.TestFoo()

System.IO.FileLoadException: 无法加载文件或程序集“Utility, Version=1.2.0.203, Culture=neutral, PublicKeyToken=764d581291d764f7”或其依赖项之一。定位的程序集的清单定义与程序集引用不匹配。(来自 HRESULT 的异常:0x80131040)

I look in my references, and I only have a reference to Utility version 1.2.0.203(the other one is old).

我查看了我的参考资料,我只有一个参考资料Utility version 1.2.0.203(另一个是旧的)。

Any suggestions on how I figure out what is trying to reference this old version of this DLL file?

关于如何找出试图引用此 DLL 文件的旧版本的任何建议?

Besides, I don't think I even have this old assembly on my hard drive. Is there any tool to search for this old versioned assembly?

此外,我认为我的硬盘驱动器上什至没有这个旧组件。有没有工具可以搜索这个旧版本的程序集?

采纳答案by Lars Truijens

The .NET Assembly loader:

.NET 程序集加载器:

  • is unable to find 1.2.0.203
  • but did find a 1.2.0.200
  • 找不到 1.2.0.203
  • 但确实找到了 1.2.0.200

This assembly does not match what was requested and therefore you get this error.

此程序集与请求的内容不匹配,因此您会收到此错误。

In simple words, it can't find the assembly that was referenced. Make sure it can find the right assembly by putting it in the GAC or in the application path. Also see https://docs.microsoft.com/archive/blogs/junfeng/the-located-assemblys-manifest-definition-with-name-xxx-dll-does-not-match-the-assembly-reference.

简单来说,它找不到被引用的程序集。通过将它放在 GAC 或应用程序路径中,确保它可以找到正确的程序集。另请参阅https://docs.microsoft.com/archive/blogs/junfeng/the-located-assemblys-manifest-definition-with-name-xxx-dll-does-not-match-the-assembly-reference

回答by Seth Petry-Johnson

You can do a couple of things to troubleshoot this issue. First, use Windows file search to search your hard drive for your assembly (.dll). Once you have a list of results, do View->Choose Details... and then check "File Version". This will display the version number in the list of results, so you can see where the old version might be coming from.

您可以执行一些操作来解决此问题。首先,使用 Windows 文件搜索在您的硬盘驱动器中搜索您的程序集 (.dll)。获得结果列表后,执行“查看”->“选择详细信息...”,然后选中“文件版本”。这将在结果列表中显示版本号,因此您可以查看旧版本的来源。

Also, like Lars said, check your GAC to see what version is listed there. This Microsoft articlestates that assemblies found in the GAC are not copied locally during a build, so you might need to remove the old version before doing a rebuild all. (See my answer to this questionfor notes on creating a batch file to do this for you)

此外,正如 Lars 所说,请检查您的 GAC 以查看那里列出的版本。这篇 Microsoft 文章指出,在构建过程中不会在 GAC 中找到的程序集在本地复制,因此您可能需要在进行全部重建之前删除旧版本。(有关创建批处理文件为您执行此操作的说明,请参阅我对此问题的回答)

If you still can't figure out where the old version is coming from, you can use the fuslogvw.exe application that ships with Visual Studio to get more information about the binding failures. Microsoft has information about this tool here. Note that you'll have to enable logging by setting the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion\EnableLogregistry key to 1.

如果您仍然无法弄清楚旧版本的来源,您可以使用 Visual Studio 附带的 fuslogvw.exe 应用程序来获取有关绑定失败的更多信息。Microsoft在此处提供了有关此工具的信息。请注意,您必须通过将HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion\EnableLog注册表项设置为 1来启用日志记录。

回答by Neal Tibrewala

I just ran across this issue and the problem was I had an old copy of the .dll in my application debug directory. You might want to also check there (instead of the GAC) to see if you see it.

我刚刚遇到了这个问题,问题是我的应用程序调试目录中有一个旧的 .dll 副本。您可能还想查看那里(而不是 GAC)以查看您是否看到它。

回答by Nathan Bedford

I just ran into this problem myself, and I found that the issue was something different than what the others have run into.

我自己刚刚遇到了这个问题,我发现这个问题与其他人遇到的问题有所不同。

I had two DLLs that my main project was referencing: CompanyClasses.dll and CompanyControls.dll. I was getting a run-time error saying:

我的主要项目引用了两个 DLL:CompanyClasses.dll 和 CompanyControls.dll。我收到一个运行时错误,说:

Could not load file or assembly 'CompanyClasses, Version=1.4.1.0, Culture=neutral, PublicKeyToken=045746ba8544160c' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference

无法加载文件或程序集“CompanyClasses, Version=1.4.1.0, Culture=neutral, PublicKeyToken=045746ba8544160c”或其依赖项之一。定位的程序集的清单定义与程序集引用不匹配

Trouble was, I didn't have any CompanyClasses.dll files on my system with a version number of 1.4.1. None in the GAC, none in the app folders...none anywhere. I searched my entire hard drive. All the CompanyClasses.dll files I had were 1.4.2.

问题是,我的系统上没有任何版本号为 1.4.1 的 CompanyClasses.dll 文件。GAC 中没有,应用程序文件夹中也没有……任何地方都没有。我搜索了我的整个硬盘。我拥有的所有 CompanyClasses.dll 文件都是 1.4.2。

The real problem, I found, was that CompanyControls.dll referenced version 1.4.1 of CompanyClasses.dll. I just recompiled CompanyControls.dll (after having it reference CompanyClasses.dll 1.4.2) and this error went away for me.

我发现真正的问题是 CompanyControls.dll 引用了 CompanyClasses.dll 的 1.4.1 版。我刚刚重新编译了 CompanyControls.dll(在它引用了 CompanyClasses.dll 1.4.2 之后),这个错误对我来说就消失了。

回答by Sire

For us, the problem was caused by something else. The license file for the DevExpress components included two lines, one for an old version of the components that was not installed on this particular computer. Removing the older version from the license file solved the issue.

对我们来说,问题是由其他原因引起的。DevExpress 组件的许可证文件包括两行,其中一行用于未安装在此特定计算机上的旧版本组件。从许可证文件中删除旧版本解决了这个问题。

The annoying part is that the error message gave no indication to what reference was causing the problems.

令人讨厌的部分是错误消息没有说明是什么引用导致了问题。

回答by nikonica

Try adding whatever's missing to the global assembly cache.

尝试将缺少的任何内容添加到全局程序集缓存中。

回答by Tad

If you are using Visual Studio, try "clean solution" and then rebuild your project.

如果您使用的是 Visual Studio,请尝试“干净的解决方案”,然后重建您的项目。

回答by Guy Starbuck

This exact same error is thrown if you try to late bind using reflection, if the assembly you are binding to gets strong-named or has its public-key token changed. The error is the same even though there is not actually any assembly found with the specified public key token.

如果您尝试使用反射进行后期绑定,如果您绑定到的程序集具有强名称或更改了其公钥标记,则会引发完全相同的错误。即使实际上没有找到任何具有指定公钥令牌的程序集,错误也是相同的。

You need to add the correct public key token (you can get it using sn -T on the dll) to resolve the error. Hope this helps.

您需要添加正确的公钥令牌(您可以在 dll 上使用 sn -T 获取它)来解决错误。希望这可以帮助。

回答by Bijimon

Mine was a very similar situation to the post by Nathan Bedford but with a slight twist. My project too referenced the changed dll in two ways. 1) Directly and 2) Indirectly by referencing a component (class library) that itself had a reference to the changed dll. Now my Visual studio project for the component(2) referenced the correct version of the changed dll. However the version number of the compnent itself was NOT changed. And as a result the install of the new version of the project failed to replace that component on the client machine.

我的情况与内森贝德福德的职位非常相似,但略有不同。我的项目也以两种方式引用了更改后的 dll。1) 直接和 2) 间接通过引用本身具有对已更改 dll 的引用的组件(类库)。现在,我的组件 (2) 的 Visual Studio 项目引用了更改后的 dll 的正确版本。然而,组件本身的版本号没有改变。结果,新版本项目的安装未能替换客户端计算机上的该组件。

End result: Direct reference (1) and Indirect reference(2) were pointing to different versions of the changed dll at the client machine. On my dev machine it worked fine.

最终结果:直接引用 (1) 和间接引用 (2) 指向客户端计算机上已更改 dll 的不同版本。在我的开发机器上它运行良好。

Resolution: Remove application; Delete all the DLLS from application folder; Re-install.Simple as that in my case.

解决方案:删除应用程序;删除应用程序文件夹中的所有 DLL;重新安装。就像我的情况一样简单。

回答by Adam

Right click the reference in VS set "Specific Version" property to True.

右键单击 VS 中的引用,将“特定版本”属性设置为 True。