Visual Studio is overwriting the correct version of NewtonSoft.Json.DLL that I have configured in both my project references and the NuGet package file with an older version when I build any other project besides the website that contains the reference.
OK. Here is the scenario:
I have a solution with a backend service and a website. The website is running on .NET 4.5 and is configured with NuGet to pull in version 6.0.1 of Newtonsoft.Json.DLL.
<package id="Newtonsoft.Json" version="6.0.1" targetFramework="net45" />
Which adds the dependenAssembly binding to the web.config file.
<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>
I can build and run this website without any problems.
I recently updated all of the class libraries and backend service from .NET 4.0 to .NET 4.5. After the update, whenever I build one of the class libraries or run/debug the backend service, the website becomes inoperable.
Could not load file or assembly 'Newtonsoft.Json' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
I tracked this down to the fact that when rebuilding one of the class libraries or running/debugging the backend service from Visual Studio, the Newtonsoft.Json.DLL gets overwritten with an older version of the file - version 4.5.11. Because of the explicit dependentAssembly binding, any time I access the website after that I get the 'Could not load ...' error mentioned above.
This would be OK if I just wanted to run one or the other of the backend service or the website, but I have to run them both together to get my application running properly. But because of this error I cannot have the backend service running at the same time as the website or the website crashes.
How do I prevent Visual Studio from overwriting the DLL?
Note that I have the reference set for only 6.0.1 across the entire solution (i.e. there is no reference anywhere to 4.5.11). And in the website I have 'Copy Local' set to true and 'Specific Version' is also set to true for the Newtonsoft.Json.DLL.
This is a known bug in Windows Azure VS Tools
Workarounds:
Remove Newtonsoft.Json.dll file from Program Files\Microsoft SDKs\Windows Azure.NET SDK\v2.3\ref\ folder.
Uninstall Windows Azure VS Tools v 2.3
My scenario was almost exactly same except that my Newtonsoft.JSON DLL was copied from different location. I verified that my solution was referencing the correct file and version but on RUN VS copied it from another location (Check this first by dragging BIN DLL into VS or properties.
In end after trying them one by one using Fusion logs I went all out replacing all references of Newtonsoft.JSON.dll that has the same incorrect version from Program files:
Quick tip: In explorer under details view add 'Product Version' as column and sort by it:
It still feels like crappy IDE behavior through if I set Specific Version for that Assembly and the file path is to the correct DLL (set by NuGet) it should really not go and override it with one from another share global location. Any comments to change Visual Studio build behavior here will be appreciated as I really don't want to do this type of manual hacks on each developers machine.