Conflicts of Newtonsoft.Json.dll between Visual Studio 12.0 Blend and the MVC 5 VS 2013 web project

I have an asp.net mvc 5 project in VS2013, I updated nuget packages all the way to the last

then I ran into this error

Error 2 The type 'Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver' exists in both 'c:\Program Files (x86)\Microsoft Visual Studio 12.0\Blend\Newtonsoft.Json.dll' and '{path to my project}\packages\Newtonsoft.Json.6.0.1\lib\net45\Newtonsoft.Json.dll' 

Does anyone else come across this.

+6
source share
4 answers

I got this error because I had an extra

 <ItemGroup> <Reference Include="Newtonsoft.Json"> <HintPath>..\packages\Newtonsoft.Json.5.0.6\lib\net45\Newtonsoft.Json.dll</HintPath> </Reference> <Reference Include="Owin"> <HintPath>..\packages\Owin.1.0\lib\net40\Owin.dll</HintPath> <Private>True</Private> </Reference> </ItemGroup> 

in my Web.csproj directly below regular links that already contain the correct link to the latest version of Newtonsoft.Json.dll. In VS, only a link to the new assembly was shown.

The solution was: I moved the valid Owin link to the main ItemGroup links and deleted the obsolete Newtonsoft.Json.dll link (manually edited the csproj file).

Cause of error message: On my machine, the HintPath from the old Newtonsoft.Json.dll does not exist, so MSBuild looked elsewhere and took the version of Blend.

(By the way: in order to find out why and where MSBuild is looking for a specific assembly, use TOOLS → Options → Projects and Solutions → Build and Run → and set the Output Size of the MSBuild Project Assembly to Details, and rebuild the project.)

+21
source

I don't use Blend at all, so I renamed Blend Newtonsoft.Json.dll to "Newtonsoft.Json.dll.bak". This was mentioned as working in Connection Error from Marcus. Marcus continues by saying that Blend cannot use Newtonsoft.Json.dll a lot, so even if you use Blend, perhaps this fix will not affect your work.

+4
source

The main reason is @blueling's answer, which I will cite:

The reason for the error message: On my machine, the HintPath from the old Newtonsoft.Json.dll does not exist, so MSBuild looked elsewhere and took the version of Blend.

I just wanted to put this as a separate answer in order to facilitate its search, as people cannot read his / her entire answer.

0
source

This type of problem mainly occurs when using the Visual Studio community. same issue that you won't find in Visual Studio Professional.

I had this problem because I used the community of professionals.

This is because, compiling the project, then it takes a link from both places, of which one of 1). "C: \ Program Files (x86) \ Microsoft Visual Studio 12.0 \ Blend \ Newtonsoft.Json.dll"

2). And more from your solution / project link. in this case, both versions are different from each other

and gives

 The type 'Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver' exists in both 'c:\Program Files (x86)\Microsoft Visual Studio 12.0\Blend\Newtonsoft.Json.dll' and '{path to my project}\packages\Newtonsoft.Json.6.0.1\lib\net45\Newtonsoft.Json.dll 

The only way to get the project to compile is to rename the NewtonSoft DLL to the Blend folder.

0
source

All Articles