Unrecognized configuration section system.web.extensions when upgrading to ASP.NET 4.0
We recently upgraded our Web application to .NET 4.0 and it seemed to be a straight forward task. Just open the solution in Visual Studio 2010 and follow the instructions in the wizard and I am done. (Detailed steps of Upgrade can be found here)
That’s most of the times true. However there could be some surprises to watch out for.
You may encounter an error for system.web.extensions at compile time or runtime.
Unrecognized configuration section system.web.extensions.
This error indicates that the system.web.extensions section is not defined anywhere in your web.config or machine.config. However if you check the machine.config in <<Windows Directory>>\Microsoft.NET\Framework\v4.0.30319\Config\machine.config you can see this section declared.
Following things are to be taken care for your web app to use the machine config from v4.0 and not earlier versions.
- Make sure that the Target Framework for all the projects in your solution are pointing to “.Net Framework 4”.
- If your Web App is running on IIS make sure that the application pool is running on a .NET Framework 4 version.
- Finally there is one more tricky part which usually is missed. Even if the error shows up after taking care of above 2 steps then open .csproj (or .vbproj for VB application) in a text editor and walkthrough to check if there is any hard coded path reference to previous versions. For example something like this
<Target Name=”AfterBuild” Condition=”’$(MvcBuildViews)’==’true’”>
<AspNetCompiler VirtualPath=”temp” ToolPath=”$(WINDIR)\Microsoft.NET\Framework\v2.0.50727” PhysicalPath=”$(ProjectDir)\..\$(ProjectName)” />
<AspNetCompiler VirtualPath=”temp” ToolPath=”$(WINDIR)\Microsoft.NET\Framework\v2.0.50727” PhysicalPath=”$(OutDir)\_PublishedWebsites\$(ProjectName)” />
</Target>
Make sure that the path is rectified to point to v4.0 directory. Even better, make it configurable so that it does not break for any v.Next versions of .NET.
Hope that helps..