Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No Way to Resolve Conflict Between dlls

Tags:

c#

warnings

build

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?

like image 332
Dagrooms Avatar asked Jun 23 '16 17:06

Dagrooms


2 Answers

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>
like image 183
Fran Avatar answered Oct 20 '22 17:10

Fran


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.

like image 40
Gábor Berkesi Avatar answered Oct 20 '22 17:10

Gábor Berkesi