Solved

Updating to RAZOR 3.0 in MVC 4

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

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.   …
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

623 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