[ACCEPTED]-How to fix "Configuration system failed to initialize/Root element is missing" error when loading config file?-config
In addition to the answer by Akram Shahda: I 6 had the same kind of problem (configuration 5 system failed to initialize / root element 4 is missing). The .config file in the AppData 3 folder was empty. The problem was solved 2 by deleting the .config file in the AppData 1 folder.
The cause of the XmlException
entitled Root element 7 is missing means the XML document (The 6 config file here) you're trying to load 5 is not formatted properly, more exactly 4 it's missing the root node.
Each XML file 3 must have a root element / node which encloses 2 all the other elements.
Your file must look 1 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 5 me i solved the issue by just going to the 4 user.config location, for this question 3 it is :
(C:\Users\company\AppData\Local\Clickbase_Corp_Sverige_AB\TouchStation.vshost.exe_Url_no1nets4fg3oy2p2q2pnwgulbvczlv33\1.1.0.12\user.config)"
I 2 deleted the config file and restarted visual 1 studio and it worked.
Hope this helps!
Thanks
In console app you should allocate < startup/> section 1 after < configSections/>
In general, the "Configuration system failed 5 to initialize" issue is likely caused by 4 invalid XML structure in the app.config. I've 3 stumbled on this from time to time when 2 attempting to port code from a "test bed" config 1 file to a service app.config file.
In my case, the connectionStrings node was 1 declared twice.
One of our customers got this error "Configuration 12 system failed to initialize" while attempting 11 to FTP from a C# project. The user was 10 NOT an admin.
Our techie customer investigated 9 and found, using ProcMon under a non-admin 8 account, that the resource used by this 7 process was the .NET machine.config file. (c:\windows\microsoft.net\framework\v4.0.30319\config\machine.config)
Our 6 customer granted local users modify rights 5 to just this config file, and it immediately 4 resolved the issue. (They do not allow 3 users to be admins, so this was necessary.)
So 2 if the above answer doesn't work for you, maybe 1 this will help.
var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
con = new OleDbConnection(config.ConnectionStrings.ConnectionStrings["connectionStr"].ConnectionString.ToString());
0
In my case, after check all, the problem 4 was in the last part of the App.config, where 3 a Log4Net configuration statement produce 2 the error.
Delete all the extra in App.config 1 and start to debug.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="[Application Name].Settings.Client" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
<applicationSettings>
<[Application Name].Settings.Client>
<setting name="IDClient" serializeAs="String">
<value>6</value>
</setting>
</[Application Name].Settings.Client>
</applicationSettings>
</configuration>
for .Net Core with Graphviz:
<configSections> <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" > </sectionGroup> </configSections> <appSettings> <add key="graphVizLocation" value="C:\Program Files (x86)\Graphviz2.38\bin" /> </appSettings> </configuration>
0
I ran into this same issue today. I was 9 trying to compile a visual studio solution 8 and could not.
The issue was that the configuration 7 file had xml name space configured. Visual 6 studio / msbuild had been happily compiling 5 with this namespace included in the application 4 configuration for many years, which makes 3 this error a bit strange.
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
But once removing 2 the namespace and visual studio / msbuild 1 were happy once again.
<configuration>
I took a copy of the user.config file, put 5 it under the resource and took a backup 4 in the application with the default values. If 3 the user.config file is not where it should 2 be, I solved this problem by creating this 1 file and typing it in.
if (!File.Exists(ConfigurationManager.OpenExeConfiguration (ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath)) //user.config path
{
using (XmlWriter writer = XmlWriter.Create(ConfigurationManager.OpenExeConfiguration (ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath)) //configuration root is added
{
writer.WriteStartElement("configuration");
writer.WriteEndElement();
writer.Flush();
}
File.WriteAllText(ConfigurationManager.OpenExeConfiguration (ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath, Properties.Resources.user);
Application.Restart(); //restart application
Environment.Exit(0);
}
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.