how to solve confilct issue of system.net.http on .net 4.6.1

kong 41 Reputation points
2022-01-26T08:22:03.397+00:00

hello

I am developing asp.net web using .net framework 4.6.1 but i stuck in a warning:

    Severity Code Description Project File Line Suppression State
Warning Found conflicts between different versions of "System.Net.Http" that could not be resolved.
There was a conflict between "System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" and "System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
    "System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" was chosen because it was primary and "System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" was not.
    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.6.2\System.Net.Http.dll].
        C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.2\System.Net.Http.dll
          Project file item includes which caused reference "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.2\System.Net.Http.dll".
            System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL
    References which depend on "System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" [C:\ave\acsdev3\xxx\appService\xxx.Web.Service\bin\System.Net.Http.dll].
        C:\ave\acsdev3\xxx\appService\xxx.Web.Service\bin\xxx.Web.Service.dll
          Project file item includes which caused reference "C:\ave\acsdev3\xxx\appService\xxx.Web.Service\bin\xxx.Web.Service.dll".
            C:\ave\acsdev3\xxx\appService\xxx.Web.Service\bin\xxx.Web.Service.dll
        C:\ave\acsdev3\xxx\appService\xxx.Web.Service\bin\System.Web.Http.dll
          Project file item includes which caused reference "C:\ave\acsdev3\xxx\appService\xxx.Web.Service\bin\System.Web.Http.dll".
            C:\ave\acsdev3\xxx\appService\xxx.Web.Service\bin\xxx.Web.Service.dll
        C:\ave\acsdev3\xxx\appService\xxx.Web.Service\bin\Microsoft.Identity.Client.dll
          Project file item includes which caused reference "C:\ave\acsdev3\xxx\appService\xxx.Web.Service\bin\Microsoft.Identity.Client.dll".
            C:\ave\acsdev3\xxx\appService\xxx.Web.Service\bin\xxx.Web.Service.dll
        C:\ave\acsdev3\xxx\appService\xxx.Web.Service\bin\System.Web.Http.WebHost.dll
          Project file item includes which caused reference "C:\ave\acsdev3\xxx\appService\xxx.Web.Service\bin\System.Web.Http.WebHost.dll".
            C:\ave\acsdev3\xxx\appService\xxx.Web.Service\bin\xxx.Web.Service.dll
        C:\ave\acsdev3\xxx\appService\xxx.Web.Service\bin\System.Net.Http.Formatting.dll
          Project file item includes which caused reference "C:\ave\acsdev3\xxx\appService\xxx.Web.Service\bin\System.Net.Http.Formatting.dll".
            C:\ave\acsdev3\xxx\appService\xxx.Web.Service\bin\xxx.Web.Service.dll xxx.Web.Service 0

 

I search a lot and find a lot of people meets this issue. can some one give me a working solution? thanks

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,417 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Yijing Sun-MSFT 7,071 Reputation points
    2022-01-27T05:36:04.273+00:00

    Hi @kong ,
    Make all references and binding redirects use 4.2.0.0 like this,you could try:

    <Reference Include="System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">  
      ...  
    </Reference>  
      
      <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>  
    

    Best regards,
    Yijing Sun


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our  documentation  to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments