0

I am seeing this warning while building my solution -

 The explicit binding redirect on "System.Net.Http, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" conflicts with an autogenerated
        binding redirect. Consider removing it from the application configuration file or disabling autogenerated binding redirects. The build will replace it with: "<bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.0.0" xmlns="urn:schemas-microsoft-com:asm.v
       1" />"

I have to use different version of System.Net.Http version 4.1.1.3 not 4.2.0.0 which I've explicitly mentioned in the App.config file. But due to AutoGenerateBindingRedirects flag, it's redirecting it to 4.2.0.0. [When I use 4.2.0.0 version, I am getting Runtime Exception while createing HttpClient. It works fine with version 4.1.1.3. Error-Message : Could not load file or assembly 'System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.]

.Net framework - 4.6.2

Q1. Is there any way to override the binding redirects which got generated via AutoGenerateBindingRedirects (as App.Config binding redirects are not working)? If yes, How?

Q2. How does AutoGenerateBindingRedirects flag decide which version a particular assembly has to redirect ? (like why System.Net.Http is being redirected to 4.2.0.0 not any other version)

Thanks in advance!!

Amit Kumar
  • 377
  • 4
  • 17
  • `I have to use different version of System.Net.Http version 4.1.1.3` why? Which .NET Framework version are you using? The oldest supported .NET Framework version right now is 4.6.2 which finally solves the redirect hell of .NET Standard 1.x, but all supported Windows OSs, ie Windows 10 and later, have newer .NET Framework versions preinstalled – Panagiotis Kanavos Jul 01 '22 at 07:29
  • The real fix is to remove the reference to the old System.Net.Http package. Right now you're trying to downgrade from the version that matches your .NET Framework version to an older one. The only way you'd need that older version is if you were using some very old third-party package with a hard-coded upper version requirement. While there were such problems with Microsoft packages 6 years ago, they were all solved since, especially once .NET Standard 2.0 became the default in .NET Framework 4.6.2. – Panagiotis Kanavos Jul 01 '22 at 07:34
  • Thanks Panagiotis for the reply. Edited the question why System.Net.Http version 4.2.0.0 is not working for us. – Amit Kumar Jul 01 '22 at 11:28
  • `is not working for us` explains nothing. What isn't working? The current problem was caused by the attempt to downgrade. Are you sure you aren't encountering [VS and old csproj format problems?](https://stackoverflow.com/questions/47570912/strange-issue-with-system-net-http-4-2-0-0-not-found) System.Net.HttpClient came with VS 2017 and a version that matched VS different from the actual package version. Downgrading won't fix this. *Up*grading to the latest version probably will – Panagiotis Kanavos Jul 01 '22 at 11:44
  • 1
    https://learn.microsoft.com/en-us/dotnet/framework/configure-apps/how-to-enable-and-disable-automatic-binding-redirection#disable-automatic-binding-redirects-in-desktop-apps – Hans Passant Jul 01 '22 at 12:14
  • Yeah, actually we are facing same VS and csproj format problems. We are referring to `System.net.Http 4.1.1.3` but our project is getting `System.Net.Http 4.2.0.0` from Visual Studio installation files. With this `4.2.0.0` version, we get exception during runtime - `Could not load file or assembly 'System.Net.Http, Version=4.2.0.0`, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. ` Also, if we just simply replace with `4.1.1.3` DLL in our output folder then we don't see any exception during runtime. Hence, we are suspecting the issue is with 4.2.0.0 version. – Amit Kumar Jul 04 '22 at 06:30
  • yes downgrading will fix it and is required in certain scenarios. system.http.net is special just have a look at this discussion where even microsoft developers propose to downgrade: https://github.com/dotnet/runtime/issues/24382#issuecomment-350036434 for any "normal reference" you don't want to downgrade and actually "fix" your references, but unfortunately that may not apply to system.net.http due to some decisions that were made during .net standard development. – Epicycle Jan 30 '23 at 16:18

0 Answers0