Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Found conflicts between System.Net.Http

I have several projects in my VS solution. Whenever I add "System.Net.Http" NuGet package to one it shows as version 4.2.0.0. Then I do the same and add same NuGet Package, however, the other says version. 4.1.1.2

enter image description here enter image description here

Then I get a warning:

Found conflicts between System.Net.Http

EDIT1:

Gathering dependency information took 1.7 sec
Attempting to resolve dependencies for package 'System.Net.Http.4.3.3' with DependencyBehavior 'Lowest'
Resolving dependency information took 0 ms
Resolving actions to install package 'System.Net.Http.4.3.3'
Resolved actions to install package 'System.Net.Http.4.3.3'
Retrieving package 'System.Net.Http 4.3.3' from 'nuget.org'.
Adding package 'System.Net.Http.4.3.3' to folder 'C:\...Service\packages'
Added package 'System.Net.Http.4.3.3' to folder 'C:\...Service\packages'
Added package 'System.Net.Http.4.3.3' to 'packages.config'
Successfully installed 'System.Net.Http 4.3.3' to ....Service
Executing nuget actions took 2.05 sec
Time Elapsed: 00:00:03.8937113

Please notice correct version installed, However => Props => Version says 4.1.1.2

enter image description here

like image 354
ShaneKm Avatar asked Feb 19 '18 12:02

ShaneKm


4 Answers

Edit: This happens only when using .NET Framework. In .NET Core/Standard land, the latest System.Net.Http assembly version seems to be always 4.1.2.0 - there is no 4.2.0.0 version available.

The issue regarding System.Net.Http is way, way more complicated then the answers here seem to imply...

  1. Yes, there is a System.Net.Http NuGet package, but no, it will not install the latest version of the same assembly (it contains version 4.1.1.2 of the System.Net.Http assembly, not 4.2.0.0).
    Update 19Mar2022: the latest NuGet package Version 4.3.4 has assembly version 4.1.1.3, assembly version 4.2.0.0 still is not directly installed.
  2. Latest Microsoft Visual Studio (or Microsoft Visual Studio Build Tools) provides version 4.2.0.0, but that does not mean your .csproj will always use it...
  3. For some reason (which I was not able to understand yet), the only guaranteed way of using 4.2.0.0 is by referencing certain NuGet packages that uses it, such us System.Buffers (version 4.5.0 worked for me).

TL;DR:

Add System.Buffers 4.5.0+ NuGet reference to your project, if you want to make sure it is using System.Net.Http 4.2.0.0 assembly.

References:

  • https://github.com/dotnet/corefx/issues/17522
  • https://github.com/dotnet/corefx/issues/25773
  • (https://github.com/dotnet/corefx/issues/22781 -broken link)
like image 120
rsenna Avatar answered Oct 31 '22 17:10

rsenna


After going through all the solutions presented here and the references cited in this answer, I finally resolved this completely. This is what I believe anyone who experiences this issue should do:

  1. Update all NuGet packages to latest.
  2. Migrate NuGet from packages.config to PackageReference as per the instructions here. Basically, for each project in your solution, In Solution Explorer, right-click on the References node or the packages.config file and select Migrate packages.config to PackageReference.... ASP.NET website projects must remain using packages.config.
  3. Remove any references to System.Net.Http that are not managed by NuGet (for projects using PackageReference, you should see the NuGet symbol enter image description here next to the reference in Solution Explorer). Replace the removed System.Net.Http references with the corresponding NuGet package if you're certain your project requires System.Net.Http (try building without it first). For projects using packages.config, take extra care to ensure that references to System.Net.Http are required and that they are also using NuGet. It may help to remove and re-add System.Net.Http via NuGet anyway (for all projects referencing it), even if already referenced using NuGet. I found that step 2 can cause some disjoint somewhere.
  4. Upgrade to .NET Framework 4.7.2 for the reasons described here. This is part of VS 2019. Otherwise, download it from here or use the Visual Studio Installer for VS 2017.
  5. Remove all the assembly bindings from all app.config and Web.config files then build your solution. app.config bindings are not required anymore. Web.config bindings will be re-added in the next step, but removing them first ensures you don't have any outdated versions in your bindings.
  6. You may now get some other conflicts at this stage. For your ASP.NET website projects, add the binding redirects to your Web.config that are given to you in the warnings. For other .NET Framework applications, for the references that you are getting warnings for, add the corresponding NuGet packages in the projects where you are getting the warnings, even if the project compiles without the reference being added. This forces the project to use the NuGet version and not the local .NET Framework version that might be getting referenced by another package. This is due to cross-over between .NET Framework and .NET Standard as alluded to by rsenna's aforementioned answer. After building, you may need to repeat this step for further references.

If you later find that you get run-time exceptions (even during unit testing) due to manifest mismatches after adding a reference somewhere, remove all the binding redirects from the website project concerned, then re-add the suggested ones given in the warning as per step 6.

I spent a lot of time trying to resolve this issue methodically, so I believe the above steps would fully resolve most people's issues, although some lateral thinking might be required for unusual cases. Let me know if this works (or doesn't work) for you.

like image 45
Neo Avatar answered Oct 31 '22 16:10

Neo


This tends to happen when you have a reference to the framework System.Net.Http, but one of your package references requires the NuGet package System.Net.Http.

See if you have a reference to that assembly, remove it and install the NuGet package instead

like image 11
erikkallen Avatar answered Oct 31 '22 15:10

erikkallen


There is a new solution to this that works as of the 9th of October 2018.

  1. You will need to update all your references to System.Net.Http to the latest version 4.3.4.
  2. You should install the package into your .Net framework solution that is causing the conflict, even if it does not explicitly require the package.
  3. If your project has the new project structure, edit it and make sure it includes the following package reference:

    <PackageReference Include="System.Net.Http" Version="4.3.4" />
    
  4. Search your solution and delete any existing binding redirects for System.Net.Http they will look as follows

    <dependentAssembly>
      <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
      <bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.0.0" />
    </dependentAssembly>
    
  5. Rebuild, the warning should now be gone and your code should build and run fine

like image 8
ObiEff Avatar answered Oct 31 '22 16:10

ObiEff