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

南楼画角 提交于 2019-12-04 05:56:46

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.)

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.

The root cause is in @blueling's answer, which I will quote:

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.

I just wanted to put this as a separate answer to make it easier to find since people may not read his/her whole answer.

This type of issue mainly occur while using Visual Studio community. the same issue you wont find on Visual Studio professional.

I had this problem because, I was using profession community.

It occur because, while compiling project, then it will takes the reference from both locations one is from 1). "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Blend\Newtonsoft.Json.dll"

2). And other is from your solution/project reference. in this case both versions are different

and it 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 project to compile is to rename the NewtonSoft dll in the Blend folder.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!