I did a Windows update and afterwards my asp.net mvc 5 application will no longer load complaining about
CS0234: The type or namespace name 'Html' does not exist in the namespace 'System.Web.Mvc'
indicating my views web.config is at fault
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Optimization"/>
<add namespace="System.Web.Routing" />
<add namespace="Ogre.Extensions" />
<add namespace="Newtonsoft.Json"/>
</namespaces>
</pages>
</system.web.webPages.razor>
Now this is very confusing. In my project itself I can see the Html
namespace, opening my assembly in ILSpy I can navigate to the bound System.Web.Mvc
and I can it as well, and the fusion log is not showing any suspicious binding errors.
It's as if just my views are getting bound (successfully) to an old version of Mvc. Why would that ever happen? How can I fix it?
Let me be clear that there have been no configuration or even code changes. This is all on my dev machine on IISExpress. It was running, I did the update and rebooted and now it is no longer running.
Here are my recent installs from the update. I could start removing them one by one, but I want to know what is actually going wrong as it feels like I'm missing part of the story.
Holy crap, thanks to @Nevada-Williford for the hint. Going in and setting my System.Web.Mvc
reference to <Private>True</Private>
(Copy Local = True) fixed it. Note, that before the update everything was working, after the update I had to modify my csproj to get it working again.
Working theory on what's going on:
Copy Local = True
and <Private>True</Private>
used to be almost, but not exactly, the same thing. The former was a Visual Studio setting, the latter an msbuild setting. If the msbuild setting was absent, the Visual Studio setting would be applied (as long as you were in VS). In this update I think they changed it so Copy Local
just reflects the presence attribute.
In our project we do not have that attribute set explicitly but Copy Local = True
so prior to the update System.Web.Mvc.dll
gets copied to the bin directory. After the update, since the attribute is missing Copy Local
shows False
and you have to set it to True
to make sure you get a local copy.
Manually setting Copy Local = True
(or adding that xml element to msbuild) fixes the issue.
Edit: While this appears to be the answer to the specific question, anyone coming here should read the comment thread and other answers - especially dmatson's - for more context, caveats, and related bugs.