Found conflicts between System.Net.Http

前端 未结 9 1391
一整个雨季
一整个雨季 2020-12-08 07:12

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

相关标签:
9条回答
  • 2020-12-08 07:14

    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

    0 讨论(0)
  • 2020-12-08 07:19

    You can force the version you're installing, so you can have both projects aligned or find a message in the output window, which would be telling you what's wrong or what your dependencies are. Since the official link lists no 4.2 release, I would do this (solution-wide)

    Install-Package System.Net.Http -Version 4.1.1
    

    Or for both projects

    Get-Project ProjectName | Install-Package System.Net.Http -Version 4.1.1
    

    Or, even better (using the last version)

    Install-Package System.Net.Http -Version 4.3.3
    

    EDIT

    Apparently you are not the first to experience this. How about the answer here? Basically you can align this section of both projects config file:

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

    You might have to adapt the token value. Just in case, could you paste the config file for both projects=

    0 讨论(0)
  • 2020-12-08 07:20

    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 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.

    0 讨论(0)
  • 2020-12-08 07:26

    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).
    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/22781
    • https://github.com/dotnet/corefx/issues/25773
    0 讨论(0)
  • 2020-12-08 07:28

    I tried out various solutions (removing the dependentAssembly OR specifying the binding redirect as well). None of them worked.

    However, the only solution which worked for me was to explicitly set Specific Version for System.Net.Http (or whatever DLL giving you version issues) to False from Visual Studio.

    0 讨论(0)
  • 2020-12-08 07:29

    The 6 steps that Neo posted above helped me solve my ASP.NET package problems! Thank you Neo! I was dealing with this for over a week.

    I just want to share my personal notes from my experience of implementing Neo's post above.

    I had an ASP.NET Web API project that targeted .Net Framework 4.6.1

    Here is what I did:

    • Upgrade to .Net Framework 4.7.2
    • Update all NuGet packages to the latest.
    • (optionally, could also do "update-package -reinstall" to make sure all packages are associated with 4.7.2)
    • Consolidate packages
    • I did not migrate from packages.config to PackageRefence, because you can't in ASP.NET
    • Removed references from System.Net.Http and others that required it, and added them as NuGet packages.
    • Removed all assembly bindings from web.config and app.config (in .Core, .Tests, .IntegrationTests libraries)
    • Added binding redirects for our in-house NuGet packages that had version numbers that ended with text (n.n.n.n-beta), but removed text and had numbers only (n.n.n.n)
    • Added this to all .csproj files:
      • MSBuild and <AutoUnifyAssemblyReferences />
      • https://github.com/Azure/azure-webjobs-sdk/issues/1598
    <PropertyGroup>
      <AutoUnifyAssemblyReferences>true</AutoUnifyAssemblyReferences>
    </PropertyGroup>
    
    • Make sure the packages in all packages.config files have the same versions in all projects in the solution
      • Make sure the versions are the same in the web.config
      • Make sure the versions are the same in the .csproj file, if applicable
    • Use Microsoft.Net.Compilers 3.1.1 (update all .csproj files in solution, including .Tests and .IntegrationTests)
    • For Data Protection API (DPAPI) that use Redis:
      • Install Microsoft.AspNetCore.DataProtection.StackExchangeRedis 2.2.5
      • StackExchange.Redis 2.0.601
      • Update System.Numerics.Vectors to 4.4.0 (note: 4.5.0 has a bug in it that prevents server connection)
    0 讨论(0)
提交回复
热议问题