Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configuration error while using Areas in ASP.NET MVC 4

After upgrading to ASP.NET MVC 4, application is breaking on accessing any webpage defined inside an Area

Error screen shot

Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: An error occurred creating the configuration section handler for system.web.webPages.razor/host: The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)

<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=__WebPagesVersion__.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
like image 748
Gopinath Avatar asked Nov 18 '12 18:11

Gopinath


People also ask

What is configuration error in asp net?

"It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS."

What is configuration in MVC?

ASP.NET MVC configuration In ASP.NET apps, configuration uses the built-in . NET configuration files, web. config in the app folder and machine. config on the server. Most ASP.NET MVC and Web API apps store their settings in the configuration file's appSettings or connectionStrings elements.


2 Answers

Added this as an answer from comment:

Change Version=_WebPagesVersion_.0.0 to Version=2.0.0.0

Alternatively see if you have any other web.config files floating about in your project and see what values are used there - I understand that sometimes if you have multiple web.config referencing different version of the hosts section it can get quite upset. BTW there is no need to uninstall MVC 3 before 4 - they co-exist happily!

like image 63
Luke Baughan Avatar answered Sep 20 '22 07:09

Luke Baughan


This is what worked for me: I had recently run Install-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform to install C#6 support for Razor, and I think it updated these libraries as well. The simple solution for me was to verify the version of the assembly in my references (there's a thought! lol). In my case, the assembly System.Web.WebPages.Razor had a "Version: 3.0.0.0" (right-click the assembly and select "Properties"). I believe whatever version is showing there, copy it over.

Before:

  <configSections>
    <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
      <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
    </sectionGroup>
  </configSections>

After:

  <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=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
    </sectionGroup>
  </configSections>

Hope that helps someone else who ended up where I did. ;)

like image 23
James Wilkins Avatar answered Sep 18 '22 07:09

James Wilkins