‘Newtonsoft.Json…’ exists in both ‘BlendNewtonsoft.Json.dll’ and ‘Solutionpackages…

I’m not able to build the solution in Visual Studio 2013.

This just happened after I updated my JSON.NET package to 6.0.1. Before that, it was working like a charm.

Any ideas?

PS: It’s probably something about OWIN. It references JSON.NET too I think, maybe dynamically?

Full error

Error   11  The type 'Newtonsoft.Json.Linq.JObject' exists in both 
'c:Program Files (x86)Microsoft Visual Studio 12.0BlendNewtonsoft.Json.dll' and
'c:UsersMeDesktopSolutions[Project]packagesNewtonsoft.Json.6.0.1libnet45Newtonsoft.Json.dll'
C:UsersMeDesktopSolutions[Project]TrendPinApp_StartStartup.Auth.cs  48  21  [Project]

I have this in my Web.Config
<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>

I have this in my .csproj
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>..packagesNewtonsoft.Json.6.0.1libnet45Newtonsoft.Json.dll</HintPath>
</Reference>

Build Output
1>------ Build started: Project: [Project].Backend, Configuration: Debug Any CPU ------
1>  All packages listed in packages.config are already installed.
1>C:Program Files (x86)MSBuild12.0binMicrosoft.Common.CurrentVersion.targets(1635,5): warning MSB3277: Found conflicts between different versions of the same dependent assembly that could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed.
1>  [Project].Backend -> C:UsersMeDesktopSolutions[Project][Project].BackendbinDebug[Project].Backend.dll
2>------ Build started: Project: [Project].Data, Configuration: Debug Any CPU ------
2>  All packages listed in packages.config are already installed.
2>  [Project].Data -> C:UsersMeDesktopSolutions[Project][Project].DatabinDebug[Project].Data.dll
3>------ Build started: Project: [Project], Configuration: Debug Any CPU ------
3>  All packages listed in packages.config are already installed.
3>C:Program Files (x86)MSBuild12.0binMicrosoft.Common.CurrentVersion.targets(1635,5): 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". Choosing "Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" arbitrarily.
3>  Consider app.config remapping of assembly "Newtonsoft.Json, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" from Version "4.5.0.0" [C:Program Files (x86)Microsoft Visual Studio 12.0BlendNewtonsoft.Json.dll] to Version "6.0.0.0" [C:UsersMeDesktopSolutions[Project]packagesNewtonsoft.Json.6.0.1libnet45Newtonsoft.Json.dll] to solve conflict and get rid of warning.
3>C:Program Files (x86)MSBuild12.0binMicrosoft.Common.CurrentVersion.targets(1635,5): warning MSB3247: Found conflicts between different versions of the same dependent assembly. In Visual Studio, double-click this warning (or select it and press Enter) to fix the conflicts; otherwise, add the following binding redirects to the "runtime" node in the application configuration file: <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"><dependentAssembly><assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" /><bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" /></dependentAssembly></assemblyBinding>
3>C:UsersMeDesktopSolutions[Project][Project]App_StartStartup.Auth.cs(48,21,48,28): error CS0433: The type 'Newtonsoft.Json.Linq.JObject' exists in both 'c:Program Files (x86)Microsoft Visual Studio 12.0BlendNewtonsoft.Json.dll' and 'c:UsersMeDesktopSolutions[Project]packagesNewtonsoft.Json.6.0.1libnet45Newtonsoft.Json.dll'
4>------ Skipped Build: Project: [Project].Tests, Configuration: Debug Any CPU ------
4>Project not selected to build for this solution configuration 
========== Build: 2 succeeded, 1 failed, 0 up-to-date, 1 skipped ==========

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

In your csproj file you will notice that there are 2 entries for Newtonsoft.Json. Remove the following entry:

<Reference Include="Newtonsoft.Json">
    <HintPath>..packagesNewtonsoft.Json.5.0.6libnet45Newtonsoft.Json.dll</HintPath>
</Reference>

Method 2

You can reflect owin and see what is it looking for in references. If it looks for specific version, you in trouble but if not, just put the version you want into application bin together with owin and hope that the signatures match. Also remember, there is GAC. So, you have room for experimentation

Method 3

I had almost the same issue after doing a merge. Turns out the merge left two references to Newtonsoft.Json in the csproj file. There was on DLL in the project and only one version in the NuGet package manager, but the csproj referenced Newtonsoft.Jason 5.0.6 and 5.0.8

I edited the csproj in notepad++ and removed the offending reference, et voila. It solved the build errors


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x