What to do when bindingredirect does not work?

0

I am in a situation reminiscent of "DLL hell". I am using a bunch of nuget packages which might muddle the circumstances, I suppose.

The complaint is at runtime that it cannot find System.Net.Http 4.0.0.0

System.IO.FileLoadException: Could not load file or assembly 'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

However, I have the following in my app.config:

 <dependentAssembly>
    <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.1.0.0" newVersion="4.1.0.0" />
  </dependentAssembly>

I would expect that any attempt to load 4.0.0.0 would load 4.1.0.0 instead but that is not happening. I do not know why.

It also might be relevant that this is happening in an old unit test. The app.config is in the unit test project.


P.S. I have seen other questions in this general area but they do not answer my issue as I am using 100% C# code here.

c#
visual-studio-2015
app-config
asked on Stack Overflow Feb 1, 2019 by Tevya

1 Answer

0

I feel your pain. I lost nearly a week this past summer on that. I'm assuming that this is a .NET Framework (i.e., non-Core) project. Remove the System.Net.Http NuGet package and all of the binding redirects for that assembly. That "should just fix" your issue (no guarantees)

If you search around, you should find a note from someone on the Microsoft product team apologizing for the mess and saying that there should never have been a NuGet package for that (I think it's in a GitHub issues discussion).

This is from memory - sorry, I don't work there anymore so I can't check my notes.

answered on Stack Overflow Feb 1, 2019 by Flydog57

User contributions licensed under CC BY-SA 3.0