title: Why does Visual Studio 2012 reference the wrong version of an assembly?
body: <p>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.</p>
  
  <p>Perhaps there are more problems lurking under the surface, but I keep getting error messages about a library called Newtonsoft.Json.</p>
  
  <p>To put this in context, the web application already referenced an old version of Newtonsoft.Json.</p>
  
  <p>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):</p>
  
  <pre><code>Failed to generate binding redirects for XXXXXXXXXX. An item with the same key has already been added.
  </code></pre>
  
  <p>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:</p>
  
  <p>I expanded the "References" folder under my web application and deleted the reference to Newtonsoft.Json.  I clicked "Add Reference" and browsed to <code>.\packages\Newtonsoft.Json.6.0.8\lib\net45Newtonsoft.Json.dll</code>.</p>
  
  <p>However, when I try to run the application, I get the following error: <code>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)</code>  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:</p>
  
  <pre><code>Path: XXXXX\Framework\bin\lib\Newtonsoft.Json.dll
  Runtime: Version v2.0.50727
  Version: 3.0.0
  </code></pre>
  
  <p>For some reason, Visual Studio is referencing a different file (a previous version for a previous .net framework) in a different directory!</p>
  
  <p>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.</p>
  
  <p>I cannot see that this file is anywhere in the GAC if that makes any difference.</p>
  
  <p>Please help me troubleshoot this issue.</p>
  
  <p><b>Edit in response to @ChrisBint's answer below</b></p>
  
  <p>There is no bindingRedirect tag in web.config for newtonsoft.json.</p>
  
  <p>Entering <code>Add-BindingRedirect</code> on the console package manager does nothing, and Visual Studio is still referencing the wrong file.</p>
  
  <p><b>Another Edit:</b></p>
  
  <p>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.</p>
  
  <p>Also, I brainfarted when I did the <code>Add-BindingRedirect</code> command last time.  I had the wrong project selected.  When I have the correct project selected, it says:</p>
  
  <pre><code>PM&gt; Add-BindingRedirect
  Add-BindingRedirect : An item with the same key has already been added.
  At line:1 char:20
  + Add-BindingRedirect &lt;&lt;&lt;&lt; 
  + CategoryInfo          : NotSpecified: (:) [Add-BindingRedirect], ArgumentException
  + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.AddBindingRedirectCommand
  </code></pre>
  
  <p><b>Another Edit:</b>
  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?</p>