Solved

Updating to RAZOR 3.0 in MVC 4

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

810 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