Coding is fun till you get bit by a bug after which it starts making fun of you. The situation worsens when the error is coming from some other place. And today it happened with me. Got the following error just when I thought everything was correctly done and let’s run the project.
Parser Error Unrecognized configuration section system.web.webPages.razor Error
Weirdo! Some of these errors are really the doomsday of the savior. Having pulled half of my hair (not literally :P) I was really running out of time for something which was needed to be setup quickly.
What’s the solution?
The problem is caused because the razor section that the error is referring to is not identified by the Razor Engine. That’s because:
- Either you added the razor section to a wrong web.config file (remember there is a web.config file for your project and other one for views folder)
- You forgot to add some important lines to your web.config which could tell the razor engine to do the honors.
I tried too many things when I finally found a solution. Just add the following lines of code to the configSections tag of your web.config file and things should be OK in no time.
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=18.104.22.168, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=22.214.171.124, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=126.96.36.199, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
Hope the little snippet helps.