How can I fix assembly version conflicts with JSON.NET after updating NuGet package references in a new ASP.NET MVC 5 project?
Here the steps I used to fix the warning:
- Unload project in VS
- Edit .csproj file
- Search for all references to Newtonsoft.Json assembly
- Found two, one to v6 and one to v5
- Replace the reference to v5 with v6
- Reload project
- Build and notice assembly reference failure
- View References and see that there are now two to Newtonsoft.Json. Remove the one that's failing to resolve.
- Rebuild - no warnings
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.
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>