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=220.127.116.11, 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:
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:
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-18.104.22.168" newVersion="22.214.171.124"/>
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.
This issue came to me today at work where two devs said they couldn’t add a new view to a project. I repro’d it right away and began investigating.
The problem was isolated to one project in the solution. I compared references between projects and compared the underlying project files. Each change that I made to bring them closer into alignment didn’t help.
As said many times, the trick to successful debugging is isolation. So I unloaded every project except for the web project being tested. The Add dialogs loaded immediately. So at this point, I had a workaround. The projects referenced by the web project (only one) could be unloaded when a new view or controller was needed.
Although this was a workaround, it’s hardly a solution. I continued down that path of figuring out why the MVC Add dialogs were causing VS to hang.
At one point, I was researching online and I noticed that the Add Controller dialog did appear. It took over 5 minutes to get to that point, but it did show. So I tried the Add View dialog and it eventually did show as well. The dropdown list for model classes was populated with every class from the referenced project. That might have been the cause of the slowdown.
Something about the dialog struck me funny. They were different between the two projects. This suggested to me that they were using different libraries. I loaded up the NuGet package manager between the two projects and saw the functional project used Razor v2.0, but the failing project used v3.2.3.
I downgraded the failing project to Razor 2.0. This caused a new problem. I no longer had context menu options to directly add controllers or views. Fortunately, I knew where to go for this fix.
In the project file is a node called ProjectTypeGuid, which tells VS what menu options to provide. I could see the non-working project was missing one of the guids. I quick copy between the projects restored the context menu options.