Razor View Error Sitecore.Mvc.AssemblyInitializer in Area project Sitecore 6.6 Technical Preview

Using Sitecore 6.6 technical preview I get the following error in the Razor view engine and its breaking my intellisense.

ASP.NET runtime error: The pre-application start initialization method InitializeAssembly on type Sitecore.Mvc.AssemblyInitializer threw an exception with the following error message: Could not read Sitecore configuration..

Our project uses heavy customization and MVC Areas to allow for a plugin type architecture. We have area projects that contain the MVC assets and views for the plugin and the intellisense was broken in one of those projects. It appears that the Sitecore.Mvc.AssemblyInitializer method is a bootstrapped method that runs during the Razor parsing of the view file in order to build the references necessary to show the intellisense.

A simplified example, where intellisense is broken in the PluginProject:

  • Solution
    • PluginProject
      • Web.config
    • SiteProject
      • App_Config
        • Include
          • Event.config
        • ConnectionStrings.config
      • Web.config

I originally thought the issue was due to an MVC 4 installation, but removing the install did nothing to fix the issue. Turns out the error message (as usual) is the key. The Sitecore.Mvc.AssemblyInitializer method is looking for the sitecore configuration in the area project web.config, which it can’t find in the portable area project because the configuration is in the main web.config of the site project.

Since we only require a reference to the Sitecore.Mvc.dll and not for that dll to be in the area project bin directory, I deleted the file and set the reference to “copy local = false”. The bootstrapper for Razor now doesn’t see the Sitecore.Mvc.dll in the bin directory and the error goes away.