Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Updating to RAZOR 3.0 in MVC 4

Posted on 2013-11-10
5
Medium Priority
?
460 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 14

Accepted Solution

by:
Dustin Hopkins earned 1500 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

Setting up LaraDock for Laravel

Learn how to set up LaraDock in a Laravel project - LaraDock gives us an easy way to run a Laravel application using Docker in a single command.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

704 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