Only one configSections element allowed per config file and if present must be the first child of the root configuration element
57,551
Solution 1
The error message itself actually details the correct fix:
configSections
must be the first child* of the root element:
*emphasis added
So just move the configSections
to the top:
<configuration>
<configSections>
<section name="Reva.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
</startup>
</configuration>
Solution 2
The Error web.config File
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings>
<add name="SQLConnect"
connectionString="Data Source=SAHIL; Initial Catalog=Demo; Integrated Security=SSPI"
providerName="System.Data.SqlClient" />
</connectionStrings>
<configSections>
<sectionnamesectionname="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework,
Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
:
:
:
:
:
:
:
</configuration>
The Error Was
To fix the error, I rearranged the elements and the error was fixed.
Related videos on Youtube
Author by
Mahesh
Updated on July 08, 2022Comments
-
Mahesh almost 2 years
I am developing the console application and when I run the .exe file, I get the following error:
system.Configuration.ConfigurationErrorsException
: Only one<configSections>
element allowed per config file and if present must be the first child of the root<configuration>
element.Here's my
App.config
file:<configuration> <startup useLegacyV2RuntimeActivationPolicy="true"> <supportedRuntime version="v4.0"/> </startup> <configSections> <section name="Reva.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" /> </configSections> <!-- ... -->
However, if I remove the following
startup
section, then it works fine<startup useLegacyV2RuntimeActivationPolicy="true"> <supportedRuntime version="v4.0"/> </startup>
-
Uwe Keim over 5 yearsIn German, the error message reads "Pro Konfigurationsdatei ist nur ein <configSections>-Element zulässig und muss, sofern vorhanden, das erste untergeordnete Element des Stamm-<configuration>-Elements sein." (Just in case, someone is googling this one).
-
-
Atron Seige almost 10 yearsToday I learnt I should read the whole error message. Thanks.
-
Piyey almost 9 years@AtronSeige me too :P
-
mbx about 7 yearsI got the same error message for a windows service and the app.config doesn't even have a "<configSections>" tag in it.
-
Daniel Hilgarth about 7 yearsPlease post your config to pastebin and Link it here
-
mbx about 7 yearsAs it turned out, my config was OK but the machine.config on that machine was broken. It even contained an SQLExpress/localhost connection string although no SQL was ever installed on that machine.
-
Kroksys about 5 yearsIf you rearranged configSections as first element and you still have same error then delete everything in "Solution/bin" folder and try again.