A few days ago I installed VS 2012, and everything seemed fine. But today I went to work on an existing MVC 3 app, and I couldn’t get it to work. It turns out there are some fairly simple changes that you need to make in the csproj and web.config files for your MVC 3 project in order to get it to work again after installing VS 2012. Hopefully this post will save someone else the same headache that I went through.
After installing VS2012, When I tried to run the MVC 3 application, I got the following yellow screen of death upon startup:
Server Error in ‘/My.Mvc.App’ Application.
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1705: Assembly ‘My.Mvc.App, Version=126.96.36.199, Culture=neutral, PublicKeyToken=null’ uses ‘System.Web.WebPages, Version=188.8.131.52, Culture=neutral, PublicKeyToken=31bf3856ad364e35′ which has a higher version than referenced assembly ‘System.Web.WebPages, Version=184.108.40.206, Culture=neutral, PublicKeyToken=31bf3856ad364e35′
So, I looked in my web config, and saw this:
<add assembly="System.Web.WebPages, Version=220.127.116.11, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
It seemed logical to me to take that 18.104.22.168 and simply make it 22.214.171.124. Problem solved? NO! Don’t do this! For reasons unclear to me, this causes an AccessViolationException to get thrown from somewhere within the Razor view engine (which is what System.Web.WebPages is).
After going down many rabbit holes, it turned out that this was a documented breaking change in the MVC 4 release notes. In order to fix the issue, you have to specify the version of System.Web.WebPages and System.Web.Helpers in your project references. In addition, you have to add a magic appSettings key to your web.config:
<add key="webpages:Version" value="126.96.36.199"/>
Once you do that, everything works fine, and you can start “roundtripping” your MVC 3 project between VS 2010 and VS 2012 as promised.
Read the release notes linked above for more details. Hope it helps.