System.Web.WebPages.Razor.Configuration.HostSection cannot be cast to

Topics: General, Installing Orchard, Troubleshooting
Jul 24, 2013 at 4:37 PM
I've got Orchard 1.4 running on my site, I've just downloaded a copy from the live server to my box with the intention of testing the upgrade to 1.6.

However, I've pointed an IIS site at the directory (.net 4 app pool) and I get this error message on every page.

Server Error in '/' Application.

[A]System.Web.WebPages.Razor.Configuration.HostSection cannot be cast to [B]System.Web.WebPages.Razor.Configuration.HostSection. Type A originates from 'System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' in the context 'Default' at location 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.WebPages.Razor\v4.0_1.0.0.0__31bf3856ad364e35\System.Web.WebPages.Razor.dll'. Type B originates from 'System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' in the context 'Default' at location 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.WebPages.Razor\v4.0_2.0.0.0__31bf3856ad364e35\System.Web.WebPages.Razor.dll'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidCastException: [A]System.Web.WebPages.Razor.Configuration.HostSection cannot be cast to [B]System.Web.WebPages.Razor.Configuration.HostSection. Type A originates from 'System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' in the context 'Default' at location 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.WebPages.Razor\v4.0_1.0.0.0__31bf3856ad364e35\System.Web.WebPages.Razor.dll'. Type B originates from 'System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' in the context 'Default' at location 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.WebPages.Razor\v4.0_2.0.0.0__31bf3856ad364e35\System.Web.WebPages.Razor.dll'.

Source Error:


Line 16: }
Line 17: </header>
Line 18: @Display(Model.Content) Line 19: @if(Model.Footer != null) {
Line 20: <footer>


-- any ideas of where to start? I see some stuff online about making changes to the web.config to tell Razor to look for MVC3 dll's not MVC4??

But nothing concrete!
Jul 24, 2013 at 4:44 PM
Nevermind! Solved it!

I did a comparison on the v1.6 web.config and the mine (v1.4).

Copied the dependantAssemblys, except for NHibernate and Autofac entry.