定位组件的清单定义与程序集引用不匹配。

时间:2022-05-14 03:03:49

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

先。FileLoadException:不能加载文件或程序集的实用程序,版本=1.2.0.200,Culture=中性,PublicKeyToken=764d581291d764f7,或其依赖项之一。定位组件的清单定义与程序集引用不匹配。(从HRESULT例外:0 x80131040)* *

at x.Foo.FooGO()

在x.Foo.FooGO()

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

在x.Foo。Foo2 Foo(字符串groupName_)。cs:123行

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

在x.Foo.UnitTests.FooTests.TestFoo FooTests()。cs: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)

先。FileLoadException:不能加载文件或程序集的实用程序,版本=1.2.0.203,Culture=中性,PublicKeyToken=764d581291d764f7,或其依赖项之一。定位组件的清单定义与程序集引用不匹配。(从HRESULT例外:0 x80131040)

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

我查阅了我的参考资料,我只参考了实用版本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?

此外,我觉得我的硬盘上甚至没有这个旧的程序集。有什么工具可以搜索这个旧版本的程序集吗?

39 个解决方案

#1


370  

The .NET Assembly loader is unable to find 1.2.0.203, but did find a 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 http://blogs.msdn.com/junfeng/archive/2004/03/25/95826.aspx.

. net程序集加载器无法找到1.2.0.203,但确实找到了1.2.0.200。这个程序集与所请求的不匹配,因此您会得到这个错误。简单地说,它找不到被引用的程序集。确保它可以通过将其放入GAC或应用程序路径中找到正确的程序集。也看到http://blogs.msdn.com/junfeng/archive/2004/03/25/95826.aspx。

#2


85  

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 article states 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 question for notes on creating a batch file to do this for you)

而且,就像佬司所说的,检查你的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\EnableLog registry key to 1.

如果你仍然不能找出旧版本的来源,你可以使用fuslogvw。exe应用程序与Visual Studio一起获得更多关于绑定失败的信息。微软在这里有关于这个工具的信息。请注意,您将必须通过设置HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ Microsoft\Fusion\EnableLog注册表键来启用日志记录。

#3


52  

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,我的主要项目是引用:companyclass。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

无法加载文件或程序集的companyclass、Version=1.4.1.0、Culture=中性、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.

问题是,我没有任何公司的课程。我系统上的dll文件的版本号为1.4.1。在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.

我发现真正的问题是公司控制。dll的参考版本1.4.1。我只是重新编译CompanyControls。dll(在有了它的参考公司类之后)。dll 1.4.2)这个错误对我来说是错误的。

#4


36  

The following redirects any assembly version to version 3.1.0.0. We have a script that will always update this reference in the App.config so we never have to deal with this issue again.

下面将任何程序集版本重定向到版本3.1.0.0。我们有一个脚本,它总是在App.config中更新这个引用,这样我们就不用再处理这个问题了。

Through reflection you can get the assembly publicKeyToken and generate this block from the .dll file itself.

通过反射,您可以获得assembly publicKeyToken并从.dll文件本身生成这个块。

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
 <dependentAssembly>
    <assemblyIdentity name="Castle.Core" publicKeyToken="407dd0808d44fbdc" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="3.1.0.0" />
  </dependentAssembly>
</assemblyBinding>

Note that without an XML namespace attribute (xmlns) this will not work.

注意,如果没有XML名称空间属性(xmlns),这将不起作用。

#5


28  

If you don't care about the version and you just want your app to run then right click on the reference and set 'specific version' to false. The other solutions wouldn't work for me. 定位组件的清单定义与程序集引用不匹配。

如果你不关心这个版本,你只想让你的应用程序运行,然后右键点击引用,并设置“特定版本”为false。其他的解决方案对我不起作用。

#6


27  

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

如果您正在使用Visual Studio,请尝试“清洁解决方案”,然后重新构建您的项目。

#7


20  

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),看看您是否看到了它。

#8


16  

I added a NuGet package, only to realize a black-box portion of my application was referencing an older version of the library.

我添加了一个NuGet包,只是为了实现我的应用程序的黑盒部分引用了旧版本的库。

I removed the package and referenced the older version's static DLL file, but the web.config file was never updated from:

我删除了这个包并引用了旧版本的静态DLL文件,但是web。配置文件从未更新过:

<dependentAssembly>
    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
    <bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="6.0.0.0" />
</dependentAssembly>

to what it should have reverted to when I uninstalled the package:

当我卸载软件包时,它应该恢复到什么状态:

<dependentAssembly>
    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
    <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.5.0.0" />
</dependentAssembly>

#9


13  

In my case it was an old version of the DLL in C:\WINDOWS\Microsoft.NET\Framework\~\Temporary ASP.NET Files\ directory. You can either delete or replace the old version, or you can remove and add back the reference to the DLL in your project. Basically, either way will create a new pointer to the temporary ASP.NET Files.

对于我来说这是一个旧版本的C:\WINDOWS\Microsoft. DLL净框架\ \ ~ \临时ASP。网络文件\目录。您可以删除或替换旧版本,也可以删除和添加对项目中DLL的引用。基本上,任何一种方法都将为临时ASP创建一个新的指针。网络文件。

#10


10  

In my case, this error occurred while running an ASP.NET application. The solution was to:

在我的例子中,这个错误是在运行ASP时发生的。网络应用程序。解决方案是:

  1. Delete the obj and bin folders in the project folder
  2. 删除项目文件夹中的obj和bin文件夹。

Clean didn't work, rebuild didn't work, all references were fine, but it wasn't writing one of the libraries. After deleting those directories, everything worked perfectly.

Clean没有工作,重新构建没有工作,所有引用都很好,但是它并不是在编写一个库。删除这些目录之后,一切都很顺利。

#11


8  

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.

令人讨厌的部分是,错误消息没有指出导致问题的原因。

#12


5  

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)来解决这个错误。希望这个有帮助。

#13


5  

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.

我的情况与内森·贝德福德(Nathan Bedford)的《邮报》非常相似,但略有不同。我的项目也以两种方式引用了修改后的dll。直接和间接引用一个组件(类库),它本身有一个对已修改的dll的引用。现在我的组件(2)的Visual studio项目引用了修改后的dll的正确版本。但是,compnent本身的版本号并没有改变。因此,该项目的新版本的安装未能将该组件替换到客户端机器上。

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;重新安装。就像我的例子一样简单。

#14


4  

I'll let someone benefit from my shear stupidity. I have some dependencies to a completely separate application (let's call this App1). The dll's from that App1 are pulled into my new application (App2). Any time I do updates in APP1, I have to create new dll's and copy them into App2. Well. . .I got tired of copying and pasting between 2 different App1 versions, so I simply added a 'NEW_' prefix to the dll's.

我要让别人从我的剪切愚蠢中获益。我对一个完全独立的应用程序有一些依赖(我们称之为App1)。从App1中提取的dll被拖入到我的新应用程序中(App2)。每当我在APP1中做更新时,我必须创建新的dll并将它们复制到App2中。我厌倦了在两个不同的App1版本之间复制和粘贴,所以我只是在dll中添加了一个“NEW_”前缀。

Well. . . I'm guessing that the build process scans the /bin folder and when it matches something up incorrectly, it barfs with the same error message as noted above. I deleted my "new_" versions and it built just dandy.

嗯。。。我猜测构建过程会扫描/bin文件夹,当它不正确地匹配某个东西时,它会发出与上面提到的相同的错误消息。我删除了我的“new_”版本,它只构建了dandy。

#15


4  

My issue was copying source code to a new machine without pulling over any of the referenced assemblies.

我的问题是将源代码复制到一台新机器上,而不需要拉过任何引用的程序集。

Nothing that I did fixed the error, so in haste, I deleted the BIN directory altogether. Rebuilt my source code, and it worked from then on out.

我没有改正错误,所以在匆忙中,我完全删除了BIN目录。重建了我的源代码,从那时起它就开始工作了。

#16


4  

I got this error while building on Team Foundation Server's build-service. It turned out I had multiple projects in my solution using different versions of the same library added with NuGet. I removed all old versions with NuGet and added the new one as reference for all.

我在构建团队基础服务器的构建服务时犯了这个错误。事实证明,我在解决方案中使用了不同版本的同一个库,并添加了NuGet。我用NuGet删除了所有旧版本,并添加了新版本作为所有的参考。

Team Foundation Server puts all DLL files in one directory, and there can only be one DLL file of a certain name at a time of course.

Team Foundation Server将所有DLL文件放在一个目录中,当然,在一个时间内只能有一个特定名称的DLL文件。

#17


3  

I just found another reason why to get this error. I cleaned my GAC from all versions of a specific library and built my project with reference to specific version deployed together with the executable. When I run the project I got this exception searching for a newer version of the library.

我找到了另一个原因来解释这个错误。我从一个特定的库的所有版本中清理了我的GAC,并在与可执行文件一起部署的特定版本中构建了我的项目。当我运行这个项目时,我得到了这个异常,搜索一个新版本的库。

The reason was publisher policy. When I uninstalled library's versions from GAC I forgot to uninstall publisher policy assemblies as well so instead of using my locally deployed assembly the assembly loader found publisher policy in GAC which told it to search for a newer version.

原因是出版商的政策。当我从GAC卸载了库的版本时,我忘记了卸载发行者的策略程序集,所以我没有使用本地部署的程序集,而是在GAC中找到了发布者策略,它告诉它要搜索一个新的版本。

#18


3  

To me the code coverage configuration in the "Local.testtesttings" file "caused" the problem. I forgot to update the files that were referenced there.

对我来说,代码覆盖配置在“本地”。testtest“文件”导致了“问题”。我忘记更新这里引用的文件了。

#19


3  

I would like to just add that I was creating a basic ASP.NET MVC 4 project and added DotNetOpenAuth.AspNet via NuGet. This resulted in the same error after I referenced a mismatching DLL file for Microsoft.Web.WebPages.OAuth.

我想补充一点,我正在创建一个基本的ASP。NET MVC 4项目并添加了DotNetOpenAuth。通过NuGet AspNet。这导致了在我引用了一个用于Microsoft.Web.WebPages.OAuth的错误匹配的DLL文件之后,出现了相同的错误。

To fix it I did a Update-Package and cleaned the solution for a full rebuild.

为了修复它,我做了一个更新包,并为一个完整的重建清理了解决方案。

That worked for me and is kind of a lazy way, but time is money:-P

这对我很有效,而且有点懒,但时间就是金钱:-P。

#20


2  

My app.config contains a

我app.config包含一个

<bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.11.0"/>

for npgsql. Somehow on the user's machine, my app.exe.config went missing. I am not sure if it was a silly user, installer glitch, or wacked out anti-virus yet. Replacing the file solved the issue.

npgsql。在用户的机器上,我的app.exe。配置失踪。我不确定这是不是一个愚蠢的用户,安装程序故障,或者是清除了反病毒。替换文件解决了这个问题。

#21


2  

clean and rebuild the solution might not replace all the dll's from the output directory.

清理和重建解决方案可能不会从输出目录中替换所有的dll。

what i'll suggest is try renaming the folder from "bin" to "oldbin" or "obj" to "oldobj"

我建议尝试将文件夹从“bin”改为“oldbin”或“obj”到“oldobj”

and then try build your silution again.

然后再试着重新洗刷你的皮肤。

incase if you are using any third party dll's those you will need to copy into newly created "bin" or "obj" folder after successful build.

如果你使用的是任何第三方dll,那么在成功构建之后,你需要复制到新创建的“bin”或“obj”文件夹中。

hope this will work for you.

希望这对你有用。

#22


1  

In your AssemblyVersion in AssemblyInfo.cs file, use a fixed version number instead of specifying *. The * will change the version number on each compilation. That was the issue for this exception in my case.

在你的汇编版本的汇编信息。cs文件,使用固定版本号而不是指定*。*将在每次编译时更改版本号。在我的案例中,这是一个例外。

#23


1  

Manually deleting the old assembly from folder location and then adding the reference to new assemblies might help.

手动从文件夹位置删除旧的程序集,然后添加对新程序集的引用可能会有帮助。

#24


1  

I got the same error... In my case it got resolved as follows:

我也有同样的错误……在我的案例中,它得到了如下的解决:

  • At first when the application was installed then the people here had used Microsoft Enterprise Library 4.1 in the application.
  • 最初安装应用程序时,这里的人在应用程序中使用了Microsoft Enterprise Library 4.1。
  • In previous week my machine was formatted & after that today when I built that application then it gave me an error that Enterprise Library assembly is missing.
  • 在前一周,我的机器被格式化了,在那之后,当我构建那个应用程序时,它给了我一个错误,那就是企业图书馆程序集丢失了。
  • Then I installed Microsoft Enterprise Library 5.0 which I got on Google as first search entry.
  • 然后我安装了Microsoft Enterprise Library 5.0,这是我在谷歌上的第一个搜索条目。
  • Then when I built the application then it gave me the above error i.e. The located assembly's manifest definition does not match the assembly reference.
  • 然后,当我构建应用程序时,它给了我上面的错误,即定位程序集的清单定义与程序集引用不匹配。
  • After much of a search work & analysis, I found that application was referring 4.1.0.0 & the DLL in the bin folder was of the version 5.0.0.0
  • 在进行了大量的搜索工作和分析之后,我发现该应用程序是指4.1.0.0 & bin文件夹中的DLL是5.0.0.0版本。
  • What i did was then I installed the Microsoft Enterprise Library 4.1.
  • 我所做的就是安装了微软企业图书馆4.1。
  • Removed the previous reference(5.0) & added the 4.0 reference.
  • 删除了之前的引用(5.0)并添加了4.0的引用。
  • Built the application & voila...it worked.
  • 构建应用程序& voila…它工作。

#25


1  

Here's my method of fixing this issue.

这是我解决这个问题的方法。

  1. From the exception message, get the name of the "problem" library and the "expected" version number.
  2. 从异常消息中,获取“问题”库和“预期”版本号的名称。

定位组件的清单定义与程序集引用不匹配。

  1. Find all copies of that .dll in your solution, right-click on them, and check which version of the .dll it is.
  2. 在您的解决方案中找到那个.dll的所有副本,右键单击它们,并检查它是哪个版本的.dll。

定位组件的清单定义与程序集引用不匹配。

Okay, so in this example, my .dll is definitely 2.0.5022.0 (so the Exception version number is wrong).

好的,在这个例子中,我的。dll肯定是2.0.5022.0(所以异常版本号是错误的)。

  1. Search for the version number which was shown in the Exception message in all of the .csproj files in your solution. Replace this version number with the actual number from the dll.
  2. 搜索解决方案中所有.csproj文件中的异常消息中显示的版本号。将这个版本号替换为dll中的实际数字。

So, in this example, I would replace this...

因此,在这个例子中,我将替换这个…

<Reference Include="DocumentFormat.OpenXml, Version=2.5.5631.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />

... with this...

…用这个……

<Reference Include="DocumentFormat.OpenXml, Version=2.0.5022.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />

Job done !

完成工作!

#26


1  

In my case the problem was between the chair and the keyboard :-)

在我的例子中,问题是在椅子和键盘之间:-)

Could not load file or assembly 'DotNetOpenAuth.Core, Version=4.0.0.0,
Culture=neutral, PublicKeyToken=2780ccd10d57b246' or one of its dependencies.
The located assembly's manifest definition does not match the assembly reference.
(Exception from HRESULT: 0x80131040)

Two or more different assemblies wanted to use a different version of the DotNetOpenAuth library, and that would not be a problem. Furthermore, on my local computer a web.config was automatically updated by NuGet:

两个或多个不同的程序集想要使用不同版本的DotNetOpenAuth库,这不会是一个问题。此外,在我的本地计算机上有一个网络。配置通过NuGet自动更新:

<dependentAssembly>
    <assemblyIdentity name="DotNetOpenAuth.AspNet" publicKeyToken="2780ccd10d57b246" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.3.0.0" />
    </dependentAssembly>
    <dependentAssembly>
        <assemblyIdentity name="DotNetOpenAuth.Core" publicKeyToken="2780ccd10d57b246" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.3.0.0" />
</dependentAssembly>

Then I realized that I had forgot to copy/deploy the new web.config to the production server. So if you have manual way of deploying web.config, check it is updated. If you have completely different web.config for production server, you have to merge these dependentAssembly section in sync after using NuGet.

然后我意识到我忘记了复制/部署新web。配置到生产服务器。如果你有手动部署网络的方法。配置,检查更新。如果你有完全不同的网络。在使用NuGet之后,您必须将这些依赖的组装部分合并到生产服务器上。

#27


0  

I received this error message due to referencing an assembly that had the same name as the assembly I was building.

我收到了这个错误消息,因为引用了与我正在构建的程序集同名的程序集。

This compiled but it overwrote the referenced assembly with the current projects assembly - thus causing the error.

这是编译的,但是它覆盖了引用的程序集和当前的项目程序集——从而导致了错误。

To fix it I changed the name of the project, and the assembly properties available through right-clicking on the project and choosing 'Properties'.

为了修复它,我更改了项目的名称,并通过右键单击项目并选择“properties”来提供程序集属性。

#28


0  

I ran into this issue while using an internal package repository. I had added the main package to the internal repository, but not the dependencies of the package. Make sure you add all dependencies, dependencies of dependencies, recursive etc to your internal repository as well.

在使用内部包存储库时,我遇到了这个问题。我已经将主包添加到内部存储库,但不添加包的依赖项。确保将所有依赖项、依赖项、递归等都添加到内部存储库中。

#29


0  

I had the same issue today which prevented me from performing Add-Migration after I made changes in Entity Framework.

我今天遇到了同样的问题,在我修改了实体框架后,阻止了我执行外接程序。

I had two projects in my solution, let's call them "Client" and "Data" - a class library project which held my EF models and context. The Client referenced the Data project.

在我的解决方案中,我有两个项目,我们称它们为“客户”和“数据”——一个包含我的EF模型和上下文的类库项目。客户端引用数据项目。

I had signed both projects, and then later made changes to an EF model. After I removed the signature I were able to add the migrations, and could then signed the project anew.

我在两个项目上都签了名,然后对一个EF模型做了修改。在删除签名之后,我可以添加迁移,然后可以重新签署项目。

I hope this can be useful for someone, sparing them of prolonged frustration..

我希望这对某人是有用的,避免他们长时间的沮丧。

#30


0  

This can also occur if you are using both AssemblyInfo.cs with the AssemblyVersion tags and your .csproj file has with a different value. By either matching the AssemblyInfo or removing the section all together the problem goes away.

如果您同时使用这两种汇编信息,也会发生这种情况。使用汇编版本标记和.csproj文件的cs具有不同的值。通过匹配组合信息或删除部分,问题就消失了。

#1


370  

The .NET Assembly loader is unable to find 1.2.0.203, but did find a 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 http://blogs.msdn.com/junfeng/archive/2004/03/25/95826.aspx.

. net程序集加载器无法找到1.2.0.203,但确实找到了1.2.0.200。这个程序集与所请求的不匹配,因此您会得到这个错误。简单地说,它找不到被引用的程序集。确保它可以通过将其放入GAC或应用程序路径中找到正确的程序集。也看到http://blogs.msdn.com/junfeng/archive/2004/03/25/95826.aspx。

#2


85  

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 article states 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 question for notes on creating a batch file to do this for you)

而且,就像佬司所说的,检查你的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\EnableLog registry key to 1.

如果你仍然不能找出旧版本的来源,你可以使用fuslogvw。exe应用程序与Visual Studio一起获得更多关于绑定失败的信息。微软在这里有关于这个工具的信息。请注意,您将必须通过设置HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ Microsoft\Fusion\EnableLog注册表键来启用日志记录。

#3


52  

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,我的主要项目是引用:companyclass。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

无法加载文件或程序集的companyclass、Version=1.4.1.0、Culture=中性、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.

问题是,我没有任何公司的课程。我系统上的dll文件的版本号为1.4.1。在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.

我发现真正的问题是公司控制。dll的参考版本1.4.1。我只是重新编译CompanyControls。dll(在有了它的参考公司类之后)。dll 1.4.2)这个错误对我来说是错误的。

#4


36  

The following redirects any assembly version to version 3.1.0.0. We have a script that will always update this reference in the App.config so we never have to deal with this issue again.

下面将任何程序集版本重定向到版本3.1.0.0。我们有一个脚本,它总是在App.config中更新这个引用,这样我们就不用再处理这个问题了。

Through reflection you can get the assembly publicKeyToken and generate this block from the .dll file itself.

通过反射,您可以获得assembly publicKeyToken并从.dll文件本身生成这个块。

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
 <dependentAssembly>
    <assemblyIdentity name="Castle.Core" publicKeyToken="407dd0808d44fbdc" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="3.1.0.0" />
  </dependentAssembly>
</assemblyBinding>

Note that without an XML namespace attribute (xmlns) this will not work.

注意,如果没有XML名称空间属性(xmlns),这将不起作用。

#5


28  

If you don't care about the version and you just want your app to run then right click on the reference and set 'specific version' to false. The other solutions wouldn't work for me. 定位组件的清单定义与程序集引用不匹配。

如果你不关心这个版本,你只想让你的应用程序运行,然后右键点击引用,并设置“特定版本”为false。其他的解决方案对我不起作用。

#6


27  

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

如果您正在使用Visual Studio,请尝试“清洁解决方案”,然后重新构建您的项目。

#7


20  

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),看看您是否看到了它。

#8


16  

I added a NuGet package, only to realize a black-box portion of my application was referencing an older version of the library.

我添加了一个NuGet包,只是为了实现我的应用程序的黑盒部分引用了旧版本的库。

I removed the package and referenced the older version's static DLL file, but the web.config file was never updated from:

我删除了这个包并引用了旧版本的静态DLL文件,但是web。配置文件从未更新过:

<dependentAssembly>
    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
    <bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="6.0.0.0" />
</dependentAssembly>

to what it should have reverted to when I uninstalled the package:

当我卸载软件包时,它应该恢复到什么状态:

<dependentAssembly>
    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
    <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.5.0.0" />
</dependentAssembly>

#9


13  

In my case it was an old version of the DLL in C:\WINDOWS\Microsoft.NET\Framework\~\Temporary ASP.NET Files\ directory. You can either delete or replace the old version, or you can remove and add back the reference to the DLL in your project. Basically, either way will create a new pointer to the temporary ASP.NET Files.

对于我来说这是一个旧版本的C:\WINDOWS\Microsoft. DLL净框架\ \ ~ \临时ASP。网络文件\目录。您可以删除或替换旧版本,也可以删除和添加对项目中DLL的引用。基本上,任何一种方法都将为临时ASP创建一个新的指针。网络文件。

#10


10  

In my case, this error occurred while running an ASP.NET application. The solution was to:

在我的例子中,这个错误是在运行ASP时发生的。网络应用程序。解决方案是:

  1. Delete the obj and bin folders in the project folder
  2. 删除项目文件夹中的obj和bin文件夹。

Clean didn't work, rebuild didn't work, all references were fine, but it wasn't writing one of the libraries. After deleting those directories, everything worked perfectly.

Clean没有工作,重新构建没有工作,所有引用都很好,但是它并不是在编写一个库。删除这些目录之后,一切都很顺利。

#11


8  

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.

令人讨厌的部分是,错误消息没有指出导致问题的原因。

#12


5  

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)来解决这个错误。希望这个有帮助。

#13


5  

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.

我的情况与内森·贝德福德(Nathan Bedford)的《邮报》非常相似,但略有不同。我的项目也以两种方式引用了修改后的dll。直接和间接引用一个组件(类库),它本身有一个对已修改的dll的引用。现在我的组件(2)的Visual studio项目引用了修改后的dll的正确版本。但是,compnent本身的版本号并没有改变。因此,该项目的新版本的安装未能将该组件替换到客户端机器上。

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;重新安装。就像我的例子一样简单。

#14


4  

I'll let someone benefit from my shear stupidity. I have some dependencies to a completely separate application (let's call this App1). The dll's from that App1 are pulled into my new application (App2). Any time I do updates in APP1, I have to create new dll's and copy them into App2. Well. . .I got tired of copying and pasting between 2 different App1 versions, so I simply added a 'NEW_' prefix to the dll's.

我要让别人从我的剪切愚蠢中获益。我对一个完全独立的应用程序有一些依赖(我们称之为App1)。从App1中提取的dll被拖入到我的新应用程序中(App2)。每当我在APP1中做更新时,我必须创建新的dll并将它们复制到App2中。我厌倦了在两个不同的App1版本之间复制和粘贴,所以我只是在dll中添加了一个“NEW_”前缀。

Well. . . I'm guessing that the build process scans the /bin folder and when it matches something up incorrectly, it barfs with the same error message as noted above. I deleted my "new_" versions and it built just dandy.

嗯。。。我猜测构建过程会扫描/bin文件夹,当它不正确地匹配某个东西时,它会发出与上面提到的相同的错误消息。我删除了我的“new_”版本,它只构建了dandy。

#15


4  

My issue was copying source code to a new machine without pulling over any of the referenced assemblies.

我的问题是将源代码复制到一台新机器上,而不需要拉过任何引用的程序集。

Nothing that I did fixed the error, so in haste, I deleted the BIN directory altogether. Rebuilt my source code, and it worked from then on out.

我没有改正错误,所以在匆忙中,我完全删除了BIN目录。重建了我的源代码,从那时起它就开始工作了。

#16


4  

I got this error while building on Team Foundation Server's build-service. It turned out I had multiple projects in my solution using different versions of the same library added with NuGet. I removed all old versions with NuGet and added the new one as reference for all.

我在构建团队基础服务器的构建服务时犯了这个错误。事实证明,我在解决方案中使用了不同版本的同一个库,并添加了NuGet。我用NuGet删除了所有旧版本,并添加了新版本作为所有的参考。

Team Foundation Server puts all DLL files in one directory, and there can only be one DLL file of a certain name at a time of course.

Team Foundation Server将所有DLL文件放在一个目录中,当然,在一个时间内只能有一个特定名称的DLL文件。

#17


3  

I just found another reason why to get this error. I cleaned my GAC from all versions of a specific library and built my project with reference to specific version deployed together with the executable. When I run the project I got this exception searching for a newer version of the library.

我找到了另一个原因来解释这个错误。我从一个特定的库的所有版本中清理了我的GAC,并在与可执行文件一起部署的特定版本中构建了我的项目。当我运行这个项目时,我得到了这个异常,搜索一个新版本的库。

The reason was publisher policy. When I uninstalled library's versions from GAC I forgot to uninstall publisher policy assemblies as well so instead of using my locally deployed assembly the assembly loader found publisher policy in GAC which told it to search for a newer version.

原因是出版商的政策。当我从GAC卸载了库的版本时,我忘记了卸载发行者的策略程序集,所以我没有使用本地部署的程序集,而是在GAC中找到了发布者策略,它告诉它要搜索一个新的版本。

#18


3  

To me the code coverage configuration in the "Local.testtesttings" file "caused" the problem. I forgot to update the files that were referenced there.

对我来说,代码覆盖配置在“本地”。testtest“文件”导致了“问题”。我忘记更新这里引用的文件了。

#19


3  

I would like to just add that I was creating a basic ASP.NET MVC 4 project and added DotNetOpenAuth.AspNet via NuGet. This resulted in the same error after I referenced a mismatching DLL file for Microsoft.Web.WebPages.OAuth.

我想补充一点,我正在创建一个基本的ASP。NET MVC 4项目并添加了DotNetOpenAuth。通过NuGet AspNet。这导致了在我引用了一个用于Microsoft.Web.WebPages.OAuth的错误匹配的DLL文件之后,出现了相同的错误。

To fix it I did a Update-Package and cleaned the solution for a full rebuild.

为了修复它,我做了一个更新包,并为一个完整的重建清理了解决方案。

That worked for me and is kind of a lazy way, but time is money:-P

这对我很有效,而且有点懒,但时间就是金钱:-P。

#20


2  

My app.config contains a

我app.config包含一个

<bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.11.0"/>

for npgsql. Somehow on the user's machine, my app.exe.config went missing. I am not sure if it was a silly user, installer glitch, or wacked out anti-virus yet. Replacing the file solved the issue.

npgsql。在用户的机器上,我的app.exe。配置失踪。我不确定这是不是一个愚蠢的用户,安装程序故障,或者是清除了反病毒。替换文件解决了这个问题。

#21


2  

clean and rebuild the solution might not replace all the dll's from the output directory.

清理和重建解决方案可能不会从输出目录中替换所有的dll。

what i'll suggest is try renaming the folder from "bin" to "oldbin" or "obj" to "oldobj"

我建议尝试将文件夹从“bin”改为“oldbin”或“obj”到“oldobj”

and then try build your silution again.

然后再试着重新洗刷你的皮肤。

incase if you are using any third party dll's those you will need to copy into newly created "bin" or "obj" folder after successful build.

如果你使用的是任何第三方dll,那么在成功构建之后,你需要复制到新创建的“bin”或“obj”文件夹中。

hope this will work for you.

希望这对你有用。

#22


1  

In your AssemblyVersion in AssemblyInfo.cs file, use a fixed version number instead of specifying *. The * will change the version number on each compilation. That was the issue for this exception in my case.

在你的汇编版本的汇编信息。cs文件,使用固定版本号而不是指定*。*将在每次编译时更改版本号。在我的案例中,这是一个例外。

#23


1  

Manually deleting the old assembly from folder location and then adding the reference to new assemblies might help.

手动从文件夹位置删除旧的程序集,然后添加对新程序集的引用可能会有帮助。

#24


1  

I got the same error... In my case it got resolved as follows:

我也有同样的错误……在我的案例中,它得到了如下的解决:

  • At first when the application was installed then the people here had used Microsoft Enterprise Library 4.1 in the application.
  • 最初安装应用程序时,这里的人在应用程序中使用了Microsoft Enterprise Library 4.1。
  • In previous week my machine was formatted & after that today when I built that application then it gave me an error that Enterprise Library assembly is missing.
  • 在前一周,我的机器被格式化了,在那之后,当我构建那个应用程序时,它给了我一个错误,那就是企业图书馆程序集丢失了。
  • Then I installed Microsoft Enterprise Library 5.0 which I got on Google as first search entry.
  • 然后我安装了Microsoft Enterprise Library 5.0,这是我在谷歌上的第一个搜索条目。
  • Then when I built the application then it gave me the above error i.e. The located assembly's manifest definition does not match the assembly reference.
  • 然后,当我构建应用程序时,它给了我上面的错误,即定位程序集的清单定义与程序集引用不匹配。
  • After much of a search work & analysis, I found that application was referring 4.1.0.0 & the DLL in the bin folder was of the version 5.0.0.0
  • 在进行了大量的搜索工作和分析之后,我发现该应用程序是指4.1.0.0 & bin文件夹中的DLL是5.0.0.0版本。
  • What i did was then I installed the Microsoft Enterprise Library 4.1.
  • 我所做的就是安装了微软企业图书馆4.1。
  • Removed the previous reference(5.0) & added the 4.0 reference.
  • 删除了之前的引用(5.0)并添加了4.0的引用。
  • Built the application & voila...it worked.
  • 构建应用程序& voila…它工作。

#25


1  

Here's my method of fixing this issue.

这是我解决这个问题的方法。

  1. From the exception message, get the name of the "problem" library and the "expected" version number.
  2. 从异常消息中,获取“问题”库和“预期”版本号的名称。

定位组件的清单定义与程序集引用不匹配。

  1. Find all copies of that .dll in your solution, right-click on them, and check which version of the .dll it is.
  2. 在您的解决方案中找到那个.dll的所有副本,右键单击它们,并检查它是哪个版本的.dll。

定位组件的清单定义与程序集引用不匹配。

Okay, so in this example, my .dll is definitely 2.0.5022.0 (so the Exception version number is wrong).

好的,在这个例子中,我的。dll肯定是2.0.5022.0(所以异常版本号是错误的)。

  1. Search for the version number which was shown in the Exception message in all of the .csproj files in your solution. Replace this version number with the actual number from the dll.
  2. 搜索解决方案中所有.csproj文件中的异常消息中显示的版本号。将这个版本号替换为dll中的实际数字。

So, in this example, I would replace this...

因此,在这个例子中,我将替换这个…

<Reference Include="DocumentFormat.OpenXml, Version=2.5.5631.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />

... with this...

…用这个……

<Reference Include="DocumentFormat.OpenXml, Version=2.0.5022.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />

Job done !

完成工作!

#26


1  

In my case the problem was between the chair and the keyboard :-)

在我的例子中,问题是在椅子和键盘之间:-)

Could not load file or assembly 'DotNetOpenAuth.Core, Version=4.0.0.0,
Culture=neutral, PublicKeyToken=2780ccd10d57b246' or one of its dependencies.
The located assembly's manifest definition does not match the assembly reference.
(Exception from HRESULT: 0x80131040)

Two or more different assemblies wanted to use a different version of the DotNetOpenAuth library, and that would not be a problem. Furthermore, on my local computer a web.config was automatically updated by NuGet:

两个或多个不同的程序集想要使用不同版本的DotNetOpenAuth库,这不会是一个问题。此外,在我的本地计算机上有一个网络。配置通过NuGet自动更新:

<dependentAssembly>
    <assemblyIdentity name="DotNetOpenAuth.AspNet" publicKeyToken="2780ccd10d57b246" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.3.0.0" />
    </dependentAssembly>
    <dependentAssembly>
        <assemblyIdentity name="DotNetOpenAuth.Core" publicKeyToken="2780ccd10d57b246" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.3.0.0" />
</dependentAssembly>

Then I realized that I had forgot to copy/deploy the new web.config to the production server. So if you have manual way of deploying web.config, check it is updated. If you have completely different web.config for production server, you have to merge these dependentAssembly section in sync after using NuGet.

然后我意识到我忘记了复制/部署新web。配置到生产服务器。如果你有手动部署网络的方法。配置,检查更新。如果你有完全不同的网络。在使用NuGet之后,您必须将这些依赖的组装部分合并到生产服务器上。

#27


0  

I received this error message due to referencing an assembly that had the same name as the assembly I was building.

我收到了这个错误消息,因为引用了与我正在构建的程序集同名的程序集。

This compiled but it overwrote the referenced assembly with the current projects assembly - thus causing the error.

这是编译的,但是它覆盖了引用的程序集和当前的项目程序集——从而导致了错误。

To fix it I changed the name of the project, and the assembly properties available through right-clicking on the project and choosing 'Properties'.

为了修复它,我更改了项目的名称,并通过右键单击项目并选择“properties”来提供程序集属性。

#28


0  

I ran into this issue while using an internal package repository. I had added the main package to the internal repository, but not the dependencies of the package. Make sure you add all dependencies, dependencies of dependencies, recursive etc to your internal repository as well.

在使用内部包存储库时,我遇到了这个问题。我已经将主包添加到内部存储库,但不添加包的依赖项。确保将所有依赖项、依赖项、递归等都添加到内部存储库中。

#29


0  

I had the same issue today which prevented me from performing Add-Migration after I made changes in Entity Framework.

我今天遇到了同样的问题,在我修改了实体框架后,阻止了我执行外接程序。

I had two projects in my solution, let's call them "Client" and "Data" - a class library project which held my EF models and context. The Client referenced the Data project.

在我的解决方案中,我有两个项目,我们称它们为“客户”和“数据”——一个包含我的EF模型和上下文的类库项目。客户端引用数据项目。

I had signed both projects, and then later made changes to an EF model. After I removed the signature I were able to add the migrations, and could then signed the project anew.

我在两个项目上都签了名,然后对一个EF模型做了修改。在删除签名之后,我可以添加迁移,然后可以重新签署项目。

I hope this can be useful for someone, sparing them of prolonged frustration..

我希望这对某人是有用的,避免他们长时间的沮丧。

#30


0  

This can also occur if you are using both AssemblyInfo.cs with the AssemblyVersion tags and your .csproj file has with a different value. By either matching the AssemblyInfo or removing the section all together the problem goes away.

如果您同时使用这两种汇编信息,也会发生这种情况。使用汇编版本标记和.csproj文件的cs具有不同的值。通过匹配组合信息或删除部分,问题就消失了。