Reputation: 25775
I created a new ASP.NET MVC 5 web project in VS 2013 (Update 1) then updated all NuGet packages. When I build the project, I get the following warning:
warning MSB3243: No way to resolve conflict between "Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" and "Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed".
When I check the web.config, however, I see that a binding redirect is in place:
<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>
Which is exactly what the warning advises.
How can I fix this warning?
Upvotes: 93
Views: 127371
Reputation: 1578
Veverke mentioned that it is possible to disable generation of binding redirects by setting AutoGEneratedBindingRedirects to false. Not sure if it's a new thing since this question was posted, but there is an "Skip applying binding redirects" option in Tools/Options/Nuget Packet Manager, which can be toggled. By default it is off, meaning the redirects will be applied. However if you do this, you will have to manage any necessary binding redirects manually.
Upvotes: 0
Reputation: 1577
I upgraded from Newtonsoft.Json 11.0.1 to 12.0.2. Opening the project file in Notepad++ I discovered both
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
and
<ItemGroup>
<Reference Include="Newtonsoft.Json">
<HintPath>..\packages\Newtonsoft.Json.11.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
</ItemGroup>
I deleted the ItemGroup wrapping the reference with the hint path to version 11.0.1.
These issues can be insanely frustrating to find. What's more, developers often follow the same steps as previous project setups. The prior setups didn't encounter the issue. For whatever reason the project file occasionally is updated incorrectly.
I desperately wish Microsoft would fix these visual studio DLL hell issues from popping up. It happens far too often and causing progress to screech to a halt until it is fixed, often by trial and error.
Upvotes: 18
Reputation: 11358
No one mentioned the following, which in my understanding is the correct solution:
Go the csproj of the project where the nuget is installed, and set the AutoGEneratedBindingRedirects
to false
.
<AutoGenerateBindingRedirects>false</AutoGenerateBindingRedirects>
Upvotes: 2
Reputation:
Okay, hopefully this should help resolve any (sane) assembly reference discrepancies ...
Rejoice.
Upvotes: 8
Reputation: 83
Remember that with the binding redirection
oldVersion="0.0.0.0-6.0.0.0"
You are saying that the old versions of the dll are between version 0.0.0.0 and version 6.0.0.0.
Upvotes: 6
Reputation: 25775
Here the steps I used to fix the warning:
Upvotes: 111
Reputation: 1714
I updated my package and even reinstalled it - but I was still getting the exact same error as the OP mentioned. I manually edited the referenced dll by doing the following.
I removed the newtonsoft.json.dll from my reference, then manually deleted the .dll from the bin directoy. Then i manually copied the newtonsoft.json.dll from the nuget package folder into the project bin, then added the reference by browsing to the .dll file.
Now my project builds again.
Upvotes: 1
Reputation: 317
I had similar issue and just wanted to post an answer for others in my situation.
I have a solution running a ASP.NET Web Application with multiple other C# class lib projects.
My ASP.NET Web Application wasn't using json, but other projects where.
This is how I fixed it:
Step 2 was first of all adding a configuration information for json, that suggest that all projects, use the latest version (6) no matter what version they have. Adding the assembly binding to Web.Config is most likely the fix.
However, step 2 also cleaned up som legacy code. It turned out we have previously used an old version (5) of json in our Web Application and the NuGet folders wasn't deleted when the reference was (I suspect: manually) removed. Adding the latest json (6), removed the old folders (json v5). This might be part of the fix as well.
Upvotes: 0
Reputation: 1362
I had this problem because I updated packages, which included Microsoft.AspNet.WebApi that has a reference to Newtonsoft.Json 4.5.6 and I already had version 6 installed. It wasn't clever enough to use the version 6.
To resolve it, after the WebApi update I opened the Tools > NuGet Package Manager > Pacakge Manager Console and ran:
Update-Package Newtonsoft.Json
The log showed that the 6.0.x and 4.5.6 versions were all updated to the latest one and everything was fine.
I have a feeling this will come up again.
Upvotes: 33
Reputation: 1902
If none of the above works, try using this in web.config or app.config:
<runtime>
<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>
</runtime>
Upvotes: 13
Reputation: 297
I found to delete this section from the project file fix the problem.
<ItemGroup>
<Reference Include="Newtonsoft.Json">
<HintPath>..\packages\Newtonsoft.Json.6.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
Upvotes: 22