Search code examples
c#.netnuget

Use latest version of System.Net.Http in .Net Framework


The latest version of System.Net.Http on nuget is 4.3.4. But even the latest .Net Framework 4.8 ships with 4.2.0 of this library.

Even if I add the nuget package Visual Studio 2019 still picks up the System.Net.Http.dll from the .Net Framework installation files.

Is there any way to get around this?

.Net Core still does not have designer support for wpf and winforms that's why i need this to work with .net framework.


Solution

  • Totally agree with you that this is confusing, but at the end binding redirection is your friend here used with your app.config / web.config file.

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <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>
        </assemblyBinding>
      </runtime>
    </configuration>
    

    The above snippet forces whatever version comes in with your code that the version which is specified in "newVersion" attribute will be used.

    The table below gives you some insights on the versioning differences.

    Mapping NuGet - BindingRedirect

    Some info on the binding redirection by Microsoft itself.