7

I'm getting a wall of warnings similar to the following in my build:

No way to resolve conflict between "Newtonsoft.Json, Version=7.0.0.0" 
and "Newtonsoft.Json, Version=6.0.0.0". 
Choosing "Newtonsoft.Json, Version=7.0.0.0" arbitrarily.

I get additional warnings for the following dlls (repeats are intentional):

Microsoft.Owin
System.Web.Http
Newtonsoft.Json
System.Net.Http.Formatting
Microsoft.Owin
Microsoft.ApplicationInsights

As well as a matching message for each warning:

Consider app.config remapping of assembly to solve conflict and get rid of warning.

Finally, I get this conflict:

Microsoft.Common.CurrentVersion.targets Found conflicts between 
different versions of the same dependent assembly. 
Please set the "AutoGenerateBindingRedirects" property to true 
in the project file.

I've read every stack overflow and MSDN answer I could find for these messages. According to this answer, the best solution is to change the references that are causing the conflicted warnings to reference the same version. What seems to be the problem is that the chain of assemblies coming from some of the 53 projects in the solution depend on different assemblies with different versions. I am unable to tell which projects cause these warnings, and the binding redirects (auto-generated in every single project, I checked) have no effect on the warnings.

What can I do to resolve these build warnings?

Community
  • 1
  • 1
Dagrooms
  • 1,507
  • 2
  • 16
  • 42

3 Answers3

7

They are all the same warning and are actually telling you what to do. You can either clean up all the references in the project. If you are using NuGet, this shouldn't be too much of an issue. Go into Manage NuGet Packages. you should see duplicate packages in you list. Move the references to the older package to new version of the package. This is one way to resolve the conflicts.

The second way would be to add binding redirects for all the assemblies that are conflicted. Here's an example of a Json.net redirect.

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="7.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
Fran
  • 6,440
  • 1
  • 23
  • 35
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/115449/discussion-between-dagrooms-and-fran). – Dagrooms Jun 23 '16 at 20:27
7

I encountered this warning and found a solution.

There was a duplicated reference in the csproj file.

<Reference Include="Newtonsoft.Json">
  <HintPath>..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>

After a NuGet update, only the first one refreshed to the new version.

When I deleted the second one the warning disappeared.

Gábor Berkesi
  • 632
  • 5
  • 10
0

In my case, after breaking out some projects from one large solution into NuGet packages, old references to residual projects caused issues. Similar to Gábor's answer, there were duplicate references in my csproj and vbproj files, but they were conflicting <ProjectReference> and <Reference> tags. Removing the old <ProjectReference> tags fixed the issue.

Nielsvh
  • 1,151
  • 1
  • 18
  • 31