Solved

Updating to RAZOR 3.0 in MVC 4

Posted on 2013-11-10
5
454 Views
Last Modified: 2013-11-12
Hi:

I've taken the basic MVC 4 Internet package and done an update for all Nuget packages.  When I try to launch the app, I get the following error:

[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\rbs\AppData\Local\Temp\Temporary ASP.NET Files\root\ddc954c1\d11f66f6\assembly\dl3\d2c56f64\60106b14_22dece01\System.Web.WebPages.Razor.dll'.

Open in new window


Any help on how to fix this greatly appreciated.

RBS
0
Comment
Question by:RBS
  • 3
  • 2
5 Comments
 
LVL 14

Accepted Solution

by:
Dustin Hopkins earned 500 total points
ID: 39637826
Hi,
Check your root web.config assemblyBinding section. Make sure that it contains the updated versions for "System.Web.WebPages.Razor" and "System.Web.Mvc". Make sure that they exist and that the versions are correct. Should be 3.0 and 5.0. As of now the code should look like the code below. BTW, the public key tokens won't change between versions.

<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>

Open in new window


Hope this helps,
Dustin
0
 

Author Closing Comment

by:RBS
ID: 39639481
Thanks Dustin - that helped.  I had to also update the web config in my views section to reference the new razor version.  Also, I was wondering - The program seems to have loaded Entity Framework 6 - though I changed it to 5 as per instructions and it seems to work.  Am I using version 5 of EF or is this something about assembly binding that I don't understand.

Thanks,
RBS
0
 
LVL 14

Expert Comment

by:Dustin Hopkins
ID: 39639783
RBS, the assemblyBindings I referenced were for System.Web.Mvc and System.Web.WebPages.Razor.

Then EF6 Setting should be towards the top in configSections and be referencing 6.0.0.0. See below:
<configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
    

Open in new window


So far as the pages section in the Views Web.Config, you should just be able to change them to reference MVC 5.0. This is because even though you started a MVC 4 project when you updated through NuGet you actually made it an MVC 5.0 project.
Here is the updated code in the Views Web.config
 <pages
        validateRequest="false"
        pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
        pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
        userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <controls>
        <add assembly="System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
      </controls>
    </pages>

Open in new window

Notice the only change I made was to set all the versions to 5.0. These changes made the OOB solution work. I hope this helps you.

Dustin
0
 
LVL 14

Expert Comment

by:Dustin Hopkins
ID: 39643122
I know you're probably beyond this by now, but I just found tutorial on asp.net for upgrading MVC4 applications to MVC5.

You can migrate a VS 2012 project using this tutorial without problems, but there is no design time support for Razor 3 in VS2012 because of  changes in the way VS loads the razor engine.

You can edit razor pages in VS2012, but it will be a plain HTML editor.

How to upgrade an MVC4 project to MVC5


Hope this helps,
Dustin
0
 

Author Comment

by:RBS
ID: 39643581
Dustin:

Thanks so much for your help.  Very informative and useful.

Regards,
RBS
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Normally the drop down box control found in the .Net framework tools is able to select just one data and value at a time, which is displayed on the text area.   But what if you want to have multiple values to be selected in the drop down box? As …
Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now