Shaver 2 - Shaver 3 MVC 5

I was working on an MVC 4 solution, and I was trying to upgrade it to MVC 5. I followed the steps described here .

I followed him, and now when I start the MVC application, he gives me this error message:

[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=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'. Type B originates from 'System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' in the context 'Default' at location 'C:\Users\User\AppData\Local\Temp\Temporary ASP.NET Files\root\665ac028\de53a189\assembly\dl3\c2c0a4b5\56e8099e_40e0ce01\System.Web.WebPages.Razor.dll'. 

Does anyone know how this could happen? or how can this be solved? Have I looked around so far? I tried changing the web.config files, to no avail ...

+54
c # asp.net-mvc razor asp.net-mvc-4 asp.net-mvc-5
Nov 13 '13 at 9:11
source share
3 answers

In Web.config (- s), verify that assemblyBinding contains the correct version for the assembly of System.Web.WebPages.Razor and System.Web.Mvc .

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

And make sure the sectionGroup razor in ConfigSections refers to the latest versions:

 <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"> <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" /> <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" /> </sectionGroup> 
+106
Nov 13 '13 at 9:17
source share

Check the version in web.config. If it gives an error again, try to clear the solution and rebuild it. Also check the Project Bin folder, delete the old links from the bin folder and restore the project solution.

+1
Sep 15 '15 at 4:27
source share

It looks like you still have a link to the Razor 2.0 dll.

Check the properties of the project links, especially "Use a specific version."

0
Nov 13 '13 at 9:14
source share



All Articles