Installed MVC 4 Beta, now my MVC 3 projects throw an error when I rebuild everything

I just installed the beta version of MVC 4, and now my MVC 3 projects (which I have not converted to 4 yet) throw an error when I rebuild everything:

Error 18 [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'.

Has anyone else come across this? Thank!

+30
asp.net-mvc-3
Feb 21 '12 at 20:09
source share
11 answers

I spent all day trying to fix this, and after systematically snatching EVERYTHING out of my project during the day, except for one base view and one base controller, he still threw this error. So I started deleting other things and found that in the โ€œMyโ€ folder, which contained MVC 3, there was a file with malicious Web.Config.

Search your project for other Web.Config files !!!

+59
Apr 05 '12 at 15:57
source share
โ€” -

I had the same problem and was able to solve it as follows:

  • Remove the System.Web.WebPages.Razor assembly from the project links.
  • Click "Save All" in the solution.
  • Add the assembly again, make sure you select version 1.0.0.0. In the link properties, select True for the specific version.
+5
Dec 03
source share

I have a solution for this:

You need to add this to your mvc 3 web.config:

  <configSections> <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" /> <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" /> </sectionGroup> </configSections> <system.web.webPages.razor> <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.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.Routing" /> <add namespace="System.Web.Helpers" /> <add namespace="System.Web.WebPages" /> <!-- Your namespace here --> </namespaces> </pages> </system.web.webPages.razor> 

Also copy bin files from

 C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 3\Assemblies C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\Assemblies 

to the folder with your project.

If you need to deploy your mvc 4 project on a server on which you did not install mvc 4, you need to do the same, but change the version from 1.0.0.0 to 2.0.0.0 in the section.

Good luck

+4
Feb 28 '12 at 12:21
source share

Steps to resolve this issue

  • First find all the web.config files in the whole project
  • In any web.config file, find the given error code 'can not be cast' and change version 2.0.0.0 to configSections of all web.config files. System.Web.WebPages.Razor.Configuration.HostSection
  • again, if an error appears, find this error code and change version 2.0.0.0 in all web.config files. Repeat this process until you resolve the version related issues.
+3
Nov 14 '13 at 7:03
source share

When you install MVC4, your mvc3 projects will point to system.web.webpages ver 2.0 ..

For MVC3 projects, remove the link to system.web.webpages ver 2.0 .. and add the link back to system.web.webpages ver 1.0 ..

Recompile and relocate and it should work again ...

Not sure why he is doing this, but he is still in beta

+1
May 31 '12 at 18:18
source share

Just in case, someone is faced with this problem. It seems that there are several different things that can cause this particular error. This is the best description of what causes the error I found. In my specific case, I added a link to the library via NuGet, and it looks like a special link to System.Web.WebPages has been added to my project. I deleted this link, rebuilt, and everything was fine.

Good luck to others with similar problems!

+1
Jun 03 '12 at 1:00
source share

Make sure that the links to System.Web.WebPages 2.0.0.0 are in root / Web.config and root / Views / Web.config

If every thing points to version 2, check to see if you have a directory called _bin_deployableAssemblies .

If you have this, then right-click on your project and select " Add Extensible Dependencies ... ", then check the MVC and Razor options to update your DLLs.

+1
Jul 17 '12 at 19:53
source share

May help someone:

  • Added correct version of DLL compatibility between breeze 1.0 and 2.0
  • Changed web.config file where it says from 3.0 to 4.0 and 1.0 to 2.0 only for MVC and razor
  • Another web.config is hidden under a view that also needs to be changed.

The above three steps helped solve the problem.

+1
Jan 09 '13 at 21:21
source share

The problem is that you may have another web.config file in the submissions directory that has repetitions pointing to old builds. When a project loads, it tries to download both versions, and then it does not work.

Try also to fix the versions in the "View's" web.config file.

For the oncoming, like me.

+1
Mar 21 '13 at 17:29
source share

It looks like you might have to update some assembly data in your web.config.

0
Feb 21 '12 at 20:10
source share

It looks like we need to change the version number if we go to mvc4 from mvc3.

I just changed the webconfig that is in the Views folder .... I need to change the version number

 <configuration> <configSections> <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" /> <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" /> </sectionGroup> </configSections> <system.web.webPages.razor> <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.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.Routing" /> </namespaces> </pages> </system.web.webPages.razor> <pages validateRequest="false" pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=**4**.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=**4**.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=**4**.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> <controls> <add assembly="System.Web.Mvc, Version=**4**.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" /> </controls> </pages> </system.web> 
0
Sep 27 '13 at 17:16
source share



All Articles