Today we started getting an error from three web applications. Two were web services and one was an ASP.NET MVC
website. The error was:
Could not load file or assembly ‘System.Net.Http, Version=2.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)
The error was occurring on this standard line in the global.asax file:
WebApiConfig.Register(GlobalConfiguration.Configuration)
Looking at the trace statements on the error page, there was a mention of a binding redirect, which I recall seeing
in the web.config of the site. That section in the web config looked like:
<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-2.2.29.0" newVersion="2.2.29.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
This config block had been in place since December, 2015. The block seems to have been added by a NuGet package
at the same time, possibly with a Framework version upgrade.
However it originally ended up there, removing the config block allowed the sites to launch again. It’s unknown
why this started happening after a Visual Studio upgrade.