Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have a asp.net mvc 5 project in VS2013, I updated the nuget packages of everything to latest

then I run 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 run into this.

like image 364
Ray Avatar asked Feb 12 '14 21:02

Ray


2 Answers

I got that error because I had an additional

<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 the usual references which already contained the correct reference to the latest Newtonsoft.Json.dll. In VS only the reference to the newer assembly was shown.

Solution was: I moved the valid Owin reference to the main references ItemGroup and deleted the outdated Newtonsoft.Json.dll reference (manually editing the csproj file).

Cause of the error message: On my machine the HintPath of the old Newtonsoft.Json.dll did not exist, therefor MSBuild was looking elsewhere and took the Blend version.

(BTW: To see why and where MSBuild is looking for a certain assembly use TOOLS -> Options -> Projects and Solutions -> Build and Run -> und set the "MSBuild project build output verbosity" setting to "Detailed" and rebuild the project.)

like image 64
blueling Avatar answered Oct 03 '22 07:10

blueling


I don't use Blend at all so I renamed the Blend Newtonsoft.Json.dll to "Newtonsoft.Json.dll.bak". This was mentioned as a work around in the Connect bug by Marcus. Marcus continues, saying that Blend may not use Newtonsoft.Json.dll much, so even if you use Blend it's possible that this fix will not affect your work.

like image 36
Rush Frisby Avatar answered Oct 03 '22 08:10

Rush Frisby