Solved

Updating to RAZOR 3.0 in MVC 4

Posted on 2013-11-10
5
455 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

910 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

21 Experts available now in Live!

Get 1:1 Help Now