ASP.NET 4.5 Web.config Error

2

My Web.config file is structured as follows:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    ...
</configuration>

The above works.

When I try to add an appSettings section as follows:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <appSettings>
    </appSettings>
    ...
</configuration>

I get the following error:

HTTP Error 500.19 - Internal Server Error The requested page cannot be accessed because the related configuration data for the page is invalid.

Error Code 0x8007000d Config Error Only one element allowed. It must be the first child element of the root element

UPDATE

if I place the <appSettings></appSettings> section after the <configSections></configSections> section, it works! What's happening?

asp.net
webforms
web-config

1 Answer

3

Your error message "Config Error Only one element allowed. It must be the first child element of the root element" is referring to the <configSections> element.

Per the MSDN:

If the configSections element is in a configuration file, the configSections element must be the first child element of the configuration element.

So, <appSettings> element will only work when it follows the <configSections>, by design.

answered on Stack Overflow Oct 9, 2014 by MikeSmithDev

User contributions licensed under CC BY-SA 3.0