Sitecore 7.2 Upgrade; Using Binding Redirects to Fix Could not load file or assembly System.Web.Helpers, Version=2

September 8, 2014

The Sitecore Upgrade from version 7.1 to 7.2 installs new dlls for MVC.  If the MVC 4 dlls are not registered in the GAC on your server, you will receive a configuration error at the end of the installation that looks like this:

Could not load file or assembly 'System.Web.Helpers, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Also the upgrade instructions for Sitecore 7.2 inexplicably don't reference the new version for the System.Web.Helpers even though it is one of the replaced dlls.  So even after following all of the configuration changes, your solution will continue to throw an error if version 2 of system.web.helpers.dll is not available.

There are a couple solutions to solve this and the most common is probably to use the standalone installer for MVC4 to register the dlls in the GAC on a server.  The problem with this installer is it will also install 700+ MB of hotfixes and files for SQL Server Express and Visual Studio.  I prefer a simpler solution than to pollute my production web servers with these unnecessary files and applications.

Solution with Binding Redirects

If you install the MVC 5 dlls to your 7.1 solution before you upgrade and use binding redirects for System.Web.Helpers and System.Web.MVC you can avoid the error, finish the installation, and get the installation results.  The MVC 5 dlls that Sitecore uses are available in the Zip archive of the Sitecore CMS site root.  However, you can probably use the following dlls from an empty MVC 5 project:

  • System.Web.Helpers.dll
  • System.Web.MVC.dll
  • System.Web.WebPages.Deployment.dll
  • System.Web.WebPages.dll
  • System.Web.WebPages.Razor.dll

After adding these dlls, you need to update the versions in the compilation -> assemblies node of the web.config:

<add assembly="System.Web.Helpers, Version=, Culture=neutral,PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Mvc, Version=, Culture=neutral,PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.WebPages, Version=, Culture=neutral,PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.WebPages.Razor, Version=, Culture=neutral,PublicKeyToken=31BF3856AD364E35" />

Finally, add two binding redirects to the runtime -> assemblyBinding node of the web.config:

<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" xmlns="urn:schemas-microsoft-com:asm.v1" />
<bindingRedirect oldVersion="" newVersion="" xmlns="urn:schemas-microsoft-com:asm.v1" />
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" xmlns="urn:schemas-microsoft-com:asm.v1" />
<bindingRedirect oldVersion="" newVersion="" xmlns="urn:schemas-microsoft-com:asm.v1" />

Now run the installation and follow all of the upgrade steps like normal.  You should replace the 2 binding redirects above with those suggested in the upgrade instructions but continue to use the 3.0.0 version for System.Web.Helpers in the compilation -> assemblies node.