46

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.0\Blend\Newtonsoft.Json.dll' and
'c:\Users\Me\Desktop\Solutions\[Project]\packages\Newtonsoft.Json.6.0.1\lib\net45\Newtonsoft.Json.dll'
C:\Users\Me\Desktop\Solutions\[Project]\TrendPin\App_Start\Startup.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>..\packages\Newtonsoft.Json.6.0.1\lib\net45\Newtonsoft.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)\MSBuild\12.0\bin\Microsoft.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:\Users\Me\Desktop\Solutions\[Project]\[Project].Backend\bin\Debug\[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:\Users\Me\Desktop\Solutions\[Project]\[Project].Data\bin\Debug\[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)\MSBuild\12.0\bin\Microsoft.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.0\Blend\Newtonsoft.Json.dll] to Version "6.0.0.0" [C:\Users\Me\Desktop\Solutions\[Project]\packages\Newtonsoft.Json.6.0.1\lib\net45\Newtonsoft.Json.dll] to solve conflict and get rid of warning.
3>C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.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:\Users\Me\Desktop\Solutions\[Project]\[Project]\App_Start\Startup.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.0\Blend\Newtonsoft.Json.dll' and 'c:\Users\Me\Desktop\Solutions\[Project]\packages\Newtonsoft.Json.6.0.1\lib\net45\Newtonsoft.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 ==========
Seregwethrin
  • 1,319
  • 2
  • 13
  • 24
  • Go to references, remove old and add manually new one to the correct dll in packages folder. Set copy=true. You have to be careful updating things. Looks like you have both versions referenced. YOu may need only to remove one – T.S. Feb 09 '14 at 00:25
  • OWIN references the older one actually, as far as I can tell. I removed OWIN and it worked. But I want them to work together. (I updated the question also) – Seregwethrin Feb 09 '14 at 00:53
  • 1
    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 bin together with owin and hope that the signatures match. Also remember, there is GAC. So, you eve room for experimentation – T.S. Feb 09 '14 at 00:59
  • Please write that as an answer and I'll accept. You've explained it good sir. – Seregwethrin Feb 09 '14 at 01:56
  • 1
    The accepted answer in this post solved it for me: http://stackoverflow.com/questions/21791597/the-type-type-exists-in-both-a-and-b/21791689#21791689 – MIP1983 Feb 15 '14 at 15:46
  • Thank you for this question. In my case it was 2 entries for Newtonsoft.Json in my project file. – Naomi Oct 16 '15 at 17:32

3 Answers3

108

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

<Reference Include="Newtonsoft.Json">
    <HintPath>..\packages\Newtonsoft.Json.5.0.6\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
Gianpiero
  • 3,349
  • 1
  • 29
  • 42
  • 2
    I have only 1 entry for Newtonsoft.Json, which unfortunately is the one you suggest removal. So can you please paste here the other reference entry? Thanks. – Blaise May 27 '14 at 15:27
  • This is perhaps not applicable in VS extension projects, see this [related discussion](https://github.com/madskristensen/WebEssentials2013/issues/1040#issuecomment-43140533). – vulcan raven Jan 10 '15 at 04:14
  • 2
    You rock! Thanks for this. – Becandoo Jun 03 '15 at 17:58
  • This can very frequently happen when none of your projects even have ANY newtonsoft references. Somehow VS seems to be able to scan dependencies inside of assembly references, and try to resolves some of those. We are still struggling with finding a solution for getting it to not copy newtonsoft dll's from (in our case) the Visual Studio blend folder. – DannyMeister Feb 16 '16 at 23:16
  • This is bullocks. Now it compiles, but you get a runtime error with invalid newtonsoft json version... – Stefan Steiger Oct 11 '16 at 12:00
  • I got essentially the same error (it was complaining about version 6 when i only had version 11 installed). I removed the section (which contained the ) and the issue went away. – mknopf Jan 08 '19 at 21:12
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

T.S.
  • 18,195
  • 11
  • 58
  • 78
  • No, it shouldn't because OP never had duplicate entry in proj file – T.S. Mar 18 '15 at 17:56
  • **Attention !!!** Before voting down on this please read comments under question and you will see that removing one reference was among my first suggestions. Now, the other answer is not applicable in ALL situations. OP's problem is different than one solved in that answer. There are no 2 entries to remove one. Op needs to find where the problem coming from before applying appropriate solution. Obviously, looking into assemblies helped to find where the incompatibility came from. Thank you. – T.S. Nov 10 '15 at 21:59
0

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

Adam Hey
  • 1,512
  • 1
  • 20
  • 24