Reputation:
I have a console application written in C# under .net 4.0 It has a bunch of variables which I want to move into App.Config (so it will be all in one place). Added this part of code to App.Config (between configuration tags):
<configuration>
<appSettings>
<add key="RemoteDirectory" value="Some Text Here"/>
</appSettings>
</configuration>
In my program trying to test it with this code
Console.WriteLine(ConfigurationManager.AppSettings["RemoteDirectory"]);
but I keep getting "Configuration system failed to initialize" error.
Upvotes: 10
Views: 66485
Reputation: 4141
Check for an Inner Exception, it seems to say exactly what is wrong with the config.
Upvotes: 0
Reputation: 1853
I also meet with this error. In my status I mixed <configSection>
and <connectionStrings>
prioritise.
I changed the order of the tags. First i write <configSection>
then <connectionStrings>
finally it fixed. Hope it will help someone.
Upvotes: 1
Reputation: 598
The exception "Configuration system failed to initialize" is raised when one declares say an "appSettings" tag or any other tag after the "configuration" root tag, before declaring the "configSections" tag.
The schema of a configuration file requires the "configSections" tag to be the first child of the root tag.
<configuration>
<configSections>
<section name="xY" type=""/>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NET Framework,Version=v4.5.2" />
</startup>
<xY></xY>
</configuration>
Upvotes: 12
Reputation: 1
Good day,
I have had that same problem in a certain PC of one of our clients. I believe it is not the same kind of problem since in my case it was that the file C:\Users\"youruser"\AppData\Local\"ProgramEditorName"\"Program.exekeytoprogram"\"ProgramVersion"\user.config file got corrupted in that particular pc. I copied that file for backup just in case and deleted the file.
It worked for me I hope it can help others.
Have a nice day,
Xabier
Upvotes: 0
Reputation: 588
Make sure that the configSections section is placed right after configuration section (First child)
Upvotes: 1
Reputation: 407
Found the issue Read the inner exception hope your code is in the try{}catch(){} block. My Inner exception reads; Only one "configSections" element allowed per config file and if present must be the first child of the root "configuration" element.
Its self explanatory Hope this helps you.
Upvotes: 0
Reputation: 4514
appSettings must be spelt right. It should be appSettings - S should be capital. I had it all lower case and got this error.
Upvotes: 0
Reputation: 494
Try looking the Inner Exception for more detailed information. It helped me out when I had this same trouble.
Also, check if the format is correct for the .net Framework you are using on your project. If you're using the framework 4.5 it should look like the one below:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<appSettings>
<add key="RemoteDirectory" value="Some Text Here" />
</appSettings>
</configuration>
Upvotes: 20
Reputation: 2085
Since it is a directory, I am assuming you are using incorrect symbols there.. perhaps a /
?
Upvotes: 0