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
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.
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>
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
In console app you should allocate < startup/> section after < configSections/>
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.
In my case, the connectionStrings node was declared twice.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With