.net 错误 CS1705:“它的版本高于引用的程序集”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9219832/
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-09-03 16:14:18  来源:igfitidea点击:

Error CS1705: "which has a higher version than referenced assembly"

.netweb-deployment

提问by jbizzle

I've been looking into this for a bit now and haven't gotten it resolved. I get the following error message:

我一直在研究这个问题,现在还没有得到解决。我收到以下错误消息:

Compiler Error Message: CS1705: Assembly 'My.Model, Version=1.1.4422.23773, Culture=neutral, 
PublicKeyToken=bfde95ba233094b2' uses 
'Common, Version=3.3.4273.24368, Culture=neutral, PublicKeyToken=bfde95ba233094b2' 
which has a higher version than referenced assembly
'Common, Version=3.3.4269.17112, Culture=neutral, PublicKeyToken=bfde95ba233094b2'

c:\WINDOWS\assembly\GAC_MSIL\Common.3.4269.17112__bfde95ba233094b2\Common.dll: 
(Location of symbol related to previous error)

The web server is running Server 2003. I went to c:\windows\assembly and did in fact notice that there were 3 versions of Common.dll listed. The highest version listed was 3.3.4269.17112

Web 服务器正在运行 Server 2003。我转到 c:\windows\assembly 并确实注意到列出了 3 个版本的 Common.dll。列出的最高版本是 3.3.4269.17112

I copied the dll with version: 3.3.4273.24368 into the assembly directory. I then re-compiled and re-deployed my code (probably overkill but oh well). When I opened my browser in a new session and went to the site URL again I still got the same message.

我将版本为 3.3.4273.24368 的 dll 复制到程序集目录中。然后我重新编译并重新部署了我的代码(可能有点矫枉过正,但好吧)。当我在新会话中打开浏览器并再次转到站点 URL 时,我仍然收到相同的消息。

I can use windows explorer and verify the higher-versioned Common.dll is now listed as well.

我可以使用 Windows 资源管理器并验证现在也列出了更高版本的 Common.dll。

What more can I look into to resolve this issue? I don't want to change the reference in my assembly to point to the older version.

我还能研究什么来解决这个问题?我不想将程序集中的引用更改为指向旧版本。

采纳答案by Jakub Konecki

3 ideas for you to try:

3个想法供您尝试:

  1. Make sure that all your dlls are compiled against the same version of Common.
  2. Check that you have project references in your solution instead of file references.
  3. Use binding redirectionsin your web.config. (Originally linked version at wayback machine)
  1. 确保所有的 dll 都是针对相同版本的 Common 编译的。
  2. 检查您的解决方案中是否有项目引用而不是文件引用。
  3. 在 web.config 中使用绑定重定向。(原链接版本在回程机

回答by Nicolas Raoul

I had this error because "Rebuild" was not really rebuilding.

我有这个错误,因为“重建”并没有真正重建。

Solution: Close Visual Studio, really go and delete the bin folder, then rebuild, it might work better.

解决方法:关闭Visual Studio,真的去删除bin文件夹,然后重建,可能效果会更好。

Also, sometimes Visual Studio lies about references, so check the HintPathin your .csprojfiles.

此外,有时 Visual Studio 会谎报引用,因此请检查HintPath您的.csproj文件。

回答by CountZero

If you're using NuGet it is worth going to 'Manage NuGet Packages For Solution', finding the package which is causing issues and hitting update. It should then bring all of the packages up to the latest version and resolve the problem.

如果您正在使用 NuGet,则值得前往“管理 NuGet 解决方案包”,找到导致问题的包并点击更新。然后它应该将所有包升级到最新版本并解决问题。

Worth a shot as it's a quick and easy.

值得一试,因为它快速而简单。

回答by Andrew Ngo

My problem was that I had 2 projects referencing 2 different copies of the same dll which had different versions. I fixed it by removing them both and making sure they were referencing the same dll file.

我的问题是我有 2 个项目引用了具有不同版本的相同 dll 的 2 个不同副本。我通过删除它们并确保它们引用相同的 dll 文件来修复它。

回答by jgong

One possible cause is that the second assembly is installed in GAC while the first assembly, with a higher version number, is added to the References of the project. To verify this, double click the assembly in the project references, and check if there is another assembly with the same name in the Object Browser.

一个可能的原因是第二个程序集安装在 GAC 中,而具有更高版本号的第一个程序集添加到项目的引用中。要验证这一点,请双击项目引用中的程序集,然后检查对象浏览器中是否存在另一个同名的程序集。

If that is the case, use the gacutil.exe utility to uninstall the second assembly from the GAC. For example, if these are 64-bit assemblies:

如果是这种情况,请使用 gacutil.exe 实用程序从 GAC 卸载第二个程序集。例如,如果这些是 64 位程序集:

C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\x64\gacutil.exe -u <assembly_name>

回答by Rahul

Go to Reference and add a new reference of your dll file which is causing the problem and make sure that all your dlls are compiled against the same version. It works for me I hope it works for you also.

转到参考并添加导致问题的 dll 文件的新参考,并确保所有 dll 都是针对相同版本编译的。它对我有用,我希望它也对你有用。

回答by Russell Speight

My team just ran into this problem within our build environment. The issue was due to a difference in the <HintPath> element of the .csproj file.

我的团队刚刚在我们的构建环境中遇到了这个问题。该问题是由于 .csproj 文件的 <HintPath> 元素不同造成的。

Our common assembly had a correct relative path to the directory containing our reference assemblies. The dependent assembly had a path from a former directory structure. The solution successfully compiled on dev machines as the GAC resolved the dependent's reference to the correct version installed in C:\Program Files. The build environment had a legacy install of the assembly (even though it should have had none) that it fell back to and thus the error. Updating the <HintPath> in a text editor corrected the problem.

我们的通用程序集具有指向包含我们参考程序集的目录的正确相对路径。依赖程序集具有来自以前目录结构的路径。该解决方案在开发机器上成功编译,因为 GAC 解析了依赖项对安装在 C:\Program Files 中的正确版本的引用。构建环境有一个旧的程序集安装(即使它应该没有),它回落到并因此出现错误。在文本编辑器中更新 <HintPath> 更正了该问题。

回答by Krishna Prasad S

The issue is seen if the nuget packages vary in multiple projects within the solution.

如果 nuget 包在解决方案中的多个项目中有所不同,则会出现此问题。

You can fix this by updating nuget packages to a common versionwith all of the PROJECTS in the SOLUTION

您可以通过将nuget 包更新为包含SOLUTION 中所有 PROJECTS的通用版本来解决此问题

回答by Haktan Enes Bi?er

I had same error. I fixed the error after installing Microsoft.AspNetCore.ALLinto test project.

我有同样的错误。安装Microsoft.AspNetCore.ALL到测试项目后,我修复了错误。

回答by gnuchu

Had a similar problem. My issue was that I had several projects within the same solution that each were referencing a specific version of a DLL but different versions. The solution was to set 'Specific Version' to false in the all of the properties of all of the references.

有类似的问题。我的问题是我在同一个解决方案中有几个项目,每个项目都引用了 DLL 的特定版本,但版本不同。解决方案是在所有引用的所有属性中将“特定版本”设置为 false。