为什么的Visual Studio 2012的参考版本错误的程序集? [英] Why does Visual Studio 2012 reference the wrong version of an assembly?

查看:246
本文介绍了为什么的Visual Studio 2012的参考版本错误的程序集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想升级,从.NET 3.5的传统Web应用程序到.NET 4.5的能使用Microsoft SignalR库的目的。如果我只是改变了.NET版本4.5,一切正常,但是当我尝试引用SignalR,所有的地狱破散。

I am trying to upgrade a legacy web application from .net 3.5 to .net 4.5 for the purposes of being able to use the Microsoft SignalR library. If I simply change the .net version to 4.5, everything works, but when I try to reference SignalR, all hell breaks loose.

也许还有在表面下潜伏着更多的问题,但我不断收到关于一个叫Newtonsoft.Json库的错误消息。

Perhaps there are more problems lurking under the surface, but I keep getting error messages about a library called Newtonsoft.Json.

要放在这一背景下,Web应用程序已经引用的是旧版本Newtonsoft.Json的。

To put this in context, the web application already referenced an old version of Newtonsoft.Json.

令人困惑的问题是,的NuGet包管理器抛出试图安装Newtonsoft.Json 6.0.8当一个错误(最新版本写这篇文章的)事实:

Confusing matters is the fact that the NuGet Package Manager throws an error when trying to install Newtonsoft.Json 6.0.8 (the latest version as of this writing):

Failed to generate binding redirects for XXXXXXXXXX. An item with the same key has already been added.

我决定,如果该工具是不会不给我找麻烦的工作,我只是手动引用的文件,这将是它的结束。的NuGet并成功安装在项目目录中的文件,所以我做了以下内容:

I decided that if the tool wasn't going to work without giving me trouble, I'd just reference the file manually and that would be the end of it. NuGet did successfully install the files in the project directory, so I did the following:

我扩大了参考文件夹下我的web应用程序,并删除了参考Newtonsoft.Json。我点击添加引用,并浏览到。\包\ Newtonsoft.Json.6.0.8 \ lib目录\ net45Newtonsoft.Json.dll

I expanded the "References" folder under my web application and deleted the reference to Newtonsoft.Json. I clicked "Add Reference" and browsed to .\packages\Newtonsoft.Json.6.0.8\lib\net45Newtonsoft.Json.dll.

然而,当我尝试运行应用程序时,我收到以下错误:无法加载文件或程序集Newtonsoft.Json,版本= 6.0.0.0,文化=中性公钥= 30ad4fe6b2a6aeed'它的依赖或之一。找到的程序集清单定义不匹配的程序集引用。 (从HRESULT异常:0x80131040)这在几个层次上没有任何意义:首先,老版Newtonsoft.Json的为3.0。其次,我添加的文件被特别标明为6.0.8版本,但奇怪的是,当我看到在Visual Studio 2012中引用的属性,我看到以下内容:

However, when I try to run the application, I get the following error: Could not load file or assembly 'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) This doesn't make sense on several levels: for starters, the old version of Newtonsoft.Json was 3.0. Second, the file I added was specifically labelled as being version 6.0.8, but strangest of all, when I look at the properties of the reference in Visual Studio 2012, I see the following:

Path: XXXXX\Framework\bin\lib\Newtonsoft.Json.dll
Runtime: Version v2.0.50727
Version: 3.0.0

由于某种原因,Visual Studio是引用一个不同的文件(previous版本为previous的.NET Framework)在不同的目录!

For some reason, Visual Studio is referencing a different file (a previous version for a previous .net framework) in a different directory!

更为复杂的事情是事实,解决方案中的其他项目使用Newtonsoft.Json的previous版本,但似乎并没有解释为什么我会点击添加引用 - >浏览,选择在6.0.8版本,并得到一个引用到不同的文件在不同的目录。

Complicating things is that fact that other "projects" within the "solution" use the previous version of Newtonsoft.Json, but that doesn't seem to explain why I would click on Add Reference -> Browse, select the 6.0.8 version and get a reference to a different file in a different directory.

我看不到这个文件是在GAC中任何地方,如果有什么差别。

I cannot see that this file is anywhere in the GAC if that makes any difference.

请帮我解决这个问题。

修改响应低于@ ChrisBint的答案

有一个在web.config中的newtonsoft.json没有bindingRedirect标签。

There is no bindingRedirect tag in web.config for newtonsoft.json.

输入添加-BindingRedirect 上的控制台软件包管理器不执行任何操作,和Visual Studio仍然引用了错误的文件。

Entering Add-BindingRedirect on the console package manager does nothing, and Visual Studio is still referencing the wrong file.

另一个编辑:

只是为了看看这个问题被隔离在一个项目中,我尝试添加另一个Web应用程序项目到我的解决方案。我添加了一个参考Newtonsoft.Json 6.0.8,看来,一切工作正常,在该项目中。

Just to see if the problem is isolated in one project, I tried adding another web application project to my solution. I added a reference to the Newtonsoft.Json 6.0.8, and it appears that everything works fine in that project.

另外,我brainfarted当我做了添加-BindingRedirect 命令最后一次。我选择了错误的项目。当我有正确的项目选择,它说:

Also, I brainfarted when I did the Add-BindingRedirect command last time. I had the wrong project selected. When I have the correct project selected, it says:

PM> Add-BindingRedirect
Add-BindingRedirect : An item with the same key has already been added.
At line:1 char:20
+ Add-BindingRedirect <<<< 
+ CategoryInfo          : NotSpecified: (:) [Add-BindingRedirect], ArgumentException
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.AddBindingRedirectCommand

另一个编辑: 正如我继续调查,我发现别的东西奇怪。如果我搜索的项目内的任何引用的名称,我发现它在XXXXX.csproj.properties上市。然而,Newtonsoft.Json是无处可寻有,也不该属性文件包含的目录。如何Visual Studio中甚至不知道去哪里找这些文件?

Another As I continue to investigate, I discovered something else odd. If I search for the name of any reference within the project, I find it listed in XXXXX.csproj.properties. However, Newtonsoft.Json is nowhere to be found there, nor does the .properties file contain the directories. How does Visual Studio even know where to look for the files?

推荐答案

现在的问题是不正确的条目在大会重定向,类似这样;

The problem is an incorrect entry in the Assembly Redirects, similar to this;

 <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/>
      </dependentAssembly>
    </assemblyBinding>

这些位于在web.config / app.config中,你应该能够与你的装配信息手动更新此。或者,您可以删除该条目,从Visual Studio

These are located in the web.config/app.config and you should be able to update this manually with the assembly information you have. Alternatively, you can remove the entry and run the following command from the Package Manager Console window within Visual Studio

添加-BindingRedirect

Add-BindingRedirect

请确保您在下拉列表中选择正确的项目。

Make sure you have the correct project selected in the Dropdown.

这篇关于为什么的Visual Studio 2012的参考版本错误的程序集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆