How to fix "Configuration system failed to initialize/Root element is missing" error when loading config file?

53,909

Solution 1

The cause of the XmlException entitled Root element is missing means the XML document (The config file here) you're trying to load is not formatted properly, more exactly it's missing the root node.

Each XML file must have a root element / node which encloses all the other elements.

Your file must look like the following:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <sectionGroup name="userSettings" 
            type="System.Configuration.UserSettingsGroup, System,
            Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
        </sectionGroup>
    </configSections>
    <userSettings>
        <WindowsFormsApplication.Properties.Settings>
        </WindowsFormsApplication.Properties.Settings>
    </userSettings>
</configuration>

Solution 2

In addition to the answer by Akram Shahda: I had the same kind of problem (configuration system failed to initialize / root element is missing). The .config file in the AppData folder was empty. The problem was solved by deleting the .config file in the AppData folder.

Solution 3

Just in case if any one reads This :

For me i solved the issue by just going to the user.config location, for this question it is :

(C:\Users\company\AppData\Local\Clickbase_Corp_Sverige_AB\TouchStation.vshost.exe_Url_no1nets4fg3oy2p2q2pnwgulbvczlv33\1.1.0.12\user.config)"

I deleted the config file and restarted visual studio and it worked.

Hope this helps!

Thanks

Solution 4

In console app you should allocate < startup/> section after < configSections/>

Solution 5

In general, the "Configuration system failed to initialize" issue is likely caused by invalid XML structure in the app.config. I've stumbled on this from time to time when attempting to port code from a "test bed" config file to a service app.config file.

Share:
53,909

Related videos on Youtube

Sangeetha
Author by

Sangeetha

Updated on July 09, 2022

Comments

  • Sangeetha
    Sangeetha almost 2 years

    I got this error in my c# windows application: "Configuration system failed to initialize".

    It was working fine. Suddenly I got this exception. It shows inner exception detail as "Root element is missing". (C:\Users\company\AppData\Local\Clickbase_Corp_Sverige_AB\TouchStation.vshost.exe_Url_no1nets4fg3oy2p2q2pnwgulbvczlv33\1.1.0.12\user.config)"}.This happens when I try to get values from Settings.cs class.

    In program.cs file the below code is written

    if (Properties.Settings.Default.CallUpgrade)
                {
                    Properties.Settings.Default.Upgrade();
                    Properties.Settings.Default.CallUpgrade = false;
                    Properties.Settings.Default.Save();                
                }
    

    And calls settings.cs class where the below code throws above exception

        [global::System.Configuration.UserScopedSettingAttribute()]
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
        [global::System.Configuration.DefaultSettingValueAttribute("True")]
    
        public bool CallUpgrade {
            get {
                return ((bool)(this["CallUpgrade"]));
            }
            set {
                this["CallUpgrade"] = value;
            }
        }
    

    The below is my entire app.config

    <configuration>
      <configSections>
        <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
          <section name="TouchStation.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
          <section name="TouchStation.TouchStation" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
        </sectionGroup>
        <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
          <section name="TouchStation.TouchStation" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
        </sectionGroup>
        <section name="SitesInfo" type="TouchServer.SitesInfoSectionHandler,TouchServerLib" />
      </configSections>
      <appSettings>
        <add key="WebRoot" value="webroot" />
        <add key="TempDir" value="temp" />
        <add key="ServerPort" value="9338" />
        <add key="ClientSettingsProvider.ServiceUri" value="" />
      </appSettings>
      <userSettings>
        <TouchStation.Properties.Settings>
          <setting name="Site" serializeAs="String">
            <value />
          </setting>
          <setting name="StationID" serializeAs="String">
            <value>0</value>
          </setting>
          <setting name="Location" serializeAs="String">
            <value />
          </setting>
          <setting name="ShutdownTime" serializeAs="String">
            <value>0000</value>
          </setting>
          <setting name="ReportStatusEvery" serializeAs="String">
            <value>0</value>
          </setting>
          <setting name="SynchronizeEvery" serializeAs="String">
            <value>10</value>
          </setting>
          <setting name="DefaultUsername" serializeAs="String">
            <value />
          </setting>
          <setting name="DefaultPassword" serializeAs="String">
            <value />
          </setting>
          <setting name="WatchdogTimeout" serializeAs="String">
            <value>60</value>
          </setting>
          <setting name="RebootOnTimeout" serializeAs="String">
            <value>False</value>
          </setting>
          <setting name="AnonymousLogin" serializeAs="String">
            <value>True</value>
          </setting>
          <setting name="RefID" serializeAs="String">
            <value />
          </setting>
          <setting name="AutoStart" serializeAs="String">
            <value>False</value>
          </setting>
          <setting name="DemoMode" serializeAs="String">
            <value>True</value>
          </setting>
          <setting name="UnlockPassword" serializeAs="String">
            <value>needle</value>
          </setting>
          <setting name="SynchronizerUsername" serializeAs="String">
            <value />
          </setting>
          <setting name="SynchronizerPassword" serializeAs="String">
            <value />
          </setting>
          <setting name="RunClientApplications" serializeAs="String">
            <value>False</value>
          </setting>
          <setting name="MapID" serializeAs="String">
            <value>0</value>
          </setting>
          <setting name="ServerName" serializeAs="String">
            <value />
          </setting>
          <setting name="CallUpgrade" serializeAs="String">
            <value>True</value>
          </setting>
          <setting name="ServerPort" serializeAs="String">
            <value>9338</value>
          </setting>
        </TouchStation.Properties.Settings>
        <TouchStation.TouchStation>
          <setting name="ServerURL" serializeAs="String">
            <value />
          </setting>
          <setting name="Site" serializeAs="String">
            <value />
          </setting>
          <setting name="StationID" serializeAs="String">
            <value>0</value>
          </setting>
          <setting name="Location" serializeAs="String">
            <value />
          </setting>
          <setting name="ShutdownTime" serializeAs="String">
            <value />
          </setting>
          <setting name="ReportStatusEvery" serializeAs="String">
            <value>0</value>
          </setting>
          <setting name="SynchronizeEvery" serializeAs="String">
            <value>0</value>
          </setting>
          <setting name="HideMouse" serializeAs="String">
            <value>False</value>
          </setting>
          <setting name="HideDesktopOnStart" serializeAs="String">
            <value>False</value>
          </setting>
          <setting name="DefaultUsername" serializeAs="String">
            <value />
          </setting>
          <setting name="DefaultPassword" serializeAs="String">
            <value />
          </setting>
          <setting name="LogServerPort" serializeAs="String">
            <value>9050</value>
          </setting>
          <setting name="WatchdogTimeout" serializeAs="String">
            <value>60</value>
          </setting>
          <setting name="RebootOnTimeout" serializeAs="String">
            <value>False</value>
          </setting>
          <setting name="AnonymousLogin" serializeAs="String">
            <value>True</value>
          </setting>
          <setting name="RefID" serializeAs="String">
            <value />
          </setting>
        </TouchStation.TouchStation>
      </userSettings>
      <applicationSettings>
        <TouchStation.TouchStation>
          <setting name="ClientSettingsURL" serializeAs="String">
            <value />
          </setting>
        </TouchStation.TouchStation>
      </applicationSettings>
      <SitesInfo>
        <sites>
          <site Name="Local" FullName="Local Site" DatabaseConnectionString="Data\local.db" />
        </sites>
      </SitesInfo>
      <system.web>
        <membership defaultProvider="ClientAuthenticationMembershipProvider">
          <providers>
            <add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" />
          </providers>
        </membership>
        <roleManager defaultProvider="ClientRoleProvider" enabled="true">
          <providers>
            <add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400" />
          </providers>
        </roleManager>
      </system.web>
    </configuration>
    

    can anyone help me in this?

    Thank You.

    Regards,

    jennie

    • Daniel Hilgarth
      Daniel Hilgarth about 13 years
      And what's the content of C:\Users\company\AppData\Local\Clickbase_Corp_Sverige_AB\Tou‌​chStation.vshost.exe‌​_Url_no1nets4fg3oy2p‌​2q2pnwgulbvczlv33\1.‌​1.0.12\user.config?
    • Akram Shahda
      Akram Shahda about 13 years
      is <?xml version="1.0" encoding="utf-8" ?> there ?
    • Sangeetha
      Sangeetha about 13 years
      Actually i dont know why this path C:\Users\company\AppData\Local\Clickbase_Corp_Sverige_AB\Tou‌​chStation.vshost.exe‌​_­Url_no1nets4fg3oy2‌​p2q2pnwgulbvczlv33\1‌​.1.0.12\user.config is showing in exception.coz ther is no such path and my application was running perfectly.suddenly i got this error
  • Henk Holterman
    Henk Holterman about 13 years
    Could be the problem, but <?xml ... ?> is not called the root-node. It is a processing instruction. <configuration> is the root.