20Apr
You receive an “The configuration section yoursection cannot be read because it is missing a section declaration” error when reading web configurations in code.
In a .Net 4.0 or later web application you may receive an error similar to
“The configuration section yoursection cannot be read because it is missing a section declaration”
when you try to get the web configuration information using Microsoft.Web.Administration.ServerManager API even when your web.config file looks alright and you do declare “yoursection” in the .Net framework web.config file located at “C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\web.config”.
This is because prior to calling GetWebConfiguration, you have to explicitly tell ServerManager to use the 4.0 Framework. For example, here is a sample code on how to do this..
ServerManager manager = new Microsoft.Web.Administration.ServerManager(true, null); config.SetMetadata("defaultManagedRuntimeVersion", "4.0.30319"); Configuration config = manager.GetWebConfiguration("yoursite", "/");
Hope this helps,
CTRL+F5

1 Response to You receive an “The configuration section yoursection cannot be read because it is missing a section declaration” error when reading web configurations in code.
serg
June 7th, 2011 at 7:50 pm
Интересно)