32

The nuget package Microsoft.Net.Http.2.0.20710.0 is causing me a build warning because of its use of System.Net.Http, Version=2.0.0.0 which is fighting with version 4 coming from another package.

What is the best way around this? Is the package Microsoft.Net.Http.2.0.20710.0 outdated, should I just reference System.Net.Http, Version=4.0.0.0 manually in my project?

The build output is:

  There was a conflict between "System.Net.Http, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" and "System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
      "System.Net.Http, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" was chosen because it was primary and "System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" was not.
      References which depend on "System.Net.Http, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" [C:\Working\MyProject\packages\Microsoft.Net.Http.2.0.20710.0\lib\net40\System.Net.Http.dll].
          C:\Working\MyProject\packages\Microsoft.Net.Http.2.0.20710.0\lib\net40\System.Net.Http.dll
            Project file item includes which caused reference "C:\Working\MyProject\packages\Microsoft.Net.Http.2.0.20710.0\lib\net40\System.Net.Http.dll".
              System.Net.Http, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL
      References which depend on "System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" [C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Net.Http.dll].
          C:\Working\MyProject\packages\Microsoft.AspNet.WebApi.Core.4.0.20710.0\lib\net40\System.Web.Http.dll
            Project file item includes which caused reference "C:\Working\MyProject\packages\Microsoft.AspNet.WebApi.Core.4.0.20710.0\lib\net40\System.Web.Http.dll".
              System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL
              System.Web.Http.WebHost, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL
          C:\Working\MyProject\packages\Microsoft.AspNet.WebApi.Client.4.0.20710.0\lib\net40\System.Net.Http.Formatting.dll
            Project file item includes which caused reference "C:\Working\MyProject\packages\Microsoft.AspNet.WebApi.Client.4.0.20710.0\lib\net40\System.Net.Http.Formatting.dll".
              System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL
              System.Net.Http.Formatting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL
              System.Web.Http.WebHost, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL
          C:\Working\MyProject\packages\Microsoft.AspNet.WebApi.WebHost.4.0.20710.0\lib\net40\System.Web.Http.WebHost.dll
            Project file item includes which caused reference "C:\Working\MyProject\packages\Microsoft.AspNet.WebApi.WebHost.4.0.20710.0\lib\net40\System.Web.Http.WebHost.dll".
              System.Web.Http.WebHost, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1578,5): warning MSB3247: Found conflicts between different versions of the same dependent assembly.
3
  • I'm having the same issue. Did you find a way around this? I had the impression that when I added all the Web API projects new, it got fixed. But now the issue is back. Commented Nov 19, 2012 at 16:48
  • 1
    Nope, still happening. It's the only warning on my CI build which is annoying. Commented Nov 19, 2012 at 16:57
  • I actually don't think it's even referenced in my project. But with the Web API it gets installed / deinstalled. Commented Nov 19, 2012 at 17:09

1 Answer 1

32
+50

You can try the workaround mentioned in this Microsoft Connect bugreport.

Or you can try and add something like this to your Web.config:

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

Edit:

This is the workaround in the Connect Bug:

modify.......: <Reference Include="System.Net.Http">
to read ......: <Reference Include="System.Net.Http, Version=4.0.0.0">

Sign up to request clarification or add additional context in comments.

4 Comments

I was looking for a better answer or confirmation of your answer, and the 4 additional upvotes you received since I started the bounty are good enough for me. Enjoy the +50.
This was also the solution to the error: The primary reference myASPWebsite.dll" could not be resolved because it has an indirect dependency on the framework assembly "System.Net.Http, Version=2.2.15.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.5". To resolve this problem, either remove the reference "myASPWebsite.dll" or retarget your application to a framework version which contains "System.Net.Http, Version=2.2.15.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
Microsoft retired Connect and all links to the bug reports are now broken. The solutions above do not work in VS 2017 .NET 4.6.2
In your Web.config, cool but where is the Web.config

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.