Share via


MVC 5 and Entity Framework 6 setup with Web API Host Error and Pages Section fix

After adding WebAPI using Nuget I get this error on an MVC 5 and Entity Framework 6 in Visual Studio 2013 Ultimate Preview:
Error 2 [A]System.Web.WebPages.Razor.Configuration.RazorPagesSection cannot be cast to [B]System.Web.WebPages.Razor.Configuration.RazorPagesSection. Type A originates from 'System.Web.WebPages.Razor, Version=1.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_1.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\Marc\AppData\Local\Temp\Temporary ASP.NET Files\temp\72269df4\f821e616\assembly\dl3\b7138798\99faddea_dac7ce01\System.Web.WebPages.Razor.dll'. C:\Users\Marc\Documents\Visual Studio 2013\Projects\ULU4\ULU4\ASPNETCOMPILER ULU4

In the View/Web.Config it contains a section Group and a section under configSections:

<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">

<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />

<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />

</sectionGroup>

</configSections>

I didn't delete any sections but I just changed the last section for just the number 1.0 to 3.0 so there should still be three lines even though below you only see the last line that changed slightly:

<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />

Finally under the system.web.webPages.razor section it looks like this in my working prototype:

<system.web.webPages.razor>

<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

It was only 1.0.0.0 which is kinda funny so between mvc4 and mvc5 the MvcWebRazorHostFactory appeared to go through 4 completely new revisions?  Oh well... I just started plugging in numbers and got lucky.

If you build successfully it should look something like:

1>------ Rebuild All started: Project: ULU4, Configuration: Debug Any CPU ------

 1> ULU4 -> C:\Users\Marc\Documents\Visual Studio 2013\Projects\DEMOMVC\DEMOMVC\bin\DEMOMVC

 1> DEMOMVC.dll

 ========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========

 

 

Here are the Nuget Packages I have installed and instructions on using Nuget for the uninitiated in Visual Studio Library Package Manager -> Package Manager Console.
To get help from nuget at powershell type: help nuget
Then one of the help commands is:

PM> get-package

 Id Version Description/Release Notes


Antlr 3.5.0.2 ANother Tool for Language Recognition, is a language tool that provides a framework for constructing recognizers, interpr...

EntityFramework 6.0.0-rc1 Entity Framework is Microsoft's recommended data access technology for new applications.

 jQuery 2.0.3 jQuery is a new kind of JavaScript Library....

Microsoft.AspNet.Mvc 5.0.0-rc1 This package contains the runtime assemblies for ASP.NET MVC. ASP.NET MVC gives you a powerful, patterns-based way to bui...

 Microsoft.AspNet.Mvc.FixedD... 5.0.0-rc1 The previous version of this package contained a workaround for a bug affecting mobile view caching in ASP.NET MVC 4. As ...

 Microsoft.AspNet.Razor 3.0.0-rc1 This package contains the runtime assemblies for ASP.NET Web Pages. ASP.NET Web Pages and the new Razor syntax provide a ...

 Microsoft.AspNet.Web.Optimi... 1.1.1 ASP.NET Optimization introduces a way to bundle and optimize CSS and JavaScript files.

 Microsoft.AspNet.WebApi.Client 5.0.0-rc1 This package adds support for formatting and content negotiation to System.Net.Http. It includes support for JSON, XML, a...

 Microsoft.AspNet.WebApi.Core 5.0.0-rc1 This package contains the core runtime assemblies for ASP.NET Web API. This package is used by hosts of the ASP.NET Web A...

 Microsoft.AspNet.WebApi.Web... 5.0.0-rc1 This package contains everything you need to host ASP.NET Web API on IIS. ASP.NET Web API is a framework that makes it ea...

 Microsoft.AspNet.WebPages 3.0.0-rc1 This package contains core runtime assemblies shared between ASP.NET MVC and ASP.NET Web Pages.

 Microsoft.Bcl 1.1.3 This packages enables projects targeting down-level platforms to use some of the types added in later versions including:...

 Microsoft.Bcl.Build 1.0.10 This package provides build infrastructure components so that projects referencing specific Microsoft packages can succes...

 Microsoft.Net.Http 2.2.15 This package includes HttpClient for sending requests over HTTP, as well as HttpRequestMessage and HttpResponseMessage fo...

 Microsoft.Web.Infrastructure 1.0.0.0 This package contains the Microsoft.Web.Infrastructure assembly that lets you dynamically register HTTP modules at run time.

 Newtonsoft.Json 5.0.6 Json.NET is a popular high-performance JSON framework for .NET

 Ninject 3.0.2-unstable-9037 Stop writing monolithic applications that make you feel like you have to move mountains to make the simplest of changes. ...

 Twitter.Bootstrap 3.0.0 Sleek, intuitive, and powerful mobile-first front-end framework for faster and easier web development. Package issues? Pl...

 WebGrease 1.5.2 Web Grease is a suite of tools for optimizing javascript, css files and images.

Finally as a side note you may have to add assemblies to get entity framework designer to work as per article: http://forums.asp.net/t/1546705.aspx

Hopefully this helps at least one person.

 

 See Also