Answered by:
Configuration system failed to initialize in console application c#

Question
-
I have a console app that I would like to use an App.config file for. I added this file to my project. I also added a reference to System.Configuration and I added the using System.Configuration to the to of my file.
When I build the app there are no problems but when I step into the code I get the following error message: configuration system failed to initialize
If I comment out the line of code that tries to access the App.config file I don't get any errors.
string fileName = ConfigurationManager.AppSettings["FileName"];
Wednesday, August 10, 2011 3:23 PM
Answers
-
Here is the answer....I didn't have an app.config file that had a <configSections></configSections> before <appSettings></appSettings>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="CustomSection" type="Samples.AspNet.CustomSection, ConfigurationErrorsException, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" allowDefinition="Everywhere" allowExeDefinition="MachineToApplication" restartOnExternalChanges="true" />
</configSections>
<appSettings>
<add key="FileName" value="FileName.csv" />
</appSettings>
<CustomSection fileName="default.txt" maxUsers="10" />
</configuration>- Marked as answer by Brian Evans Wednesday, August 10, 2011 3:33 PM
Wednesday, August 10, 2011 3:33 PM
All replies
-
Hi
Check with calling
ConfigurationManager.OpenExeConfiguration("App config path" );
If this post answers your question, please click "Mark As Answer". If this post is helpful please click "Mark as Helpful".Wednesday, August 10, 2011 3:31 PM -
Here is the answer....I didn't have an app.config file that had a <configSections></configSections> before <appSettings></appSettings>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="CustomSection" type="Samples.AspNet.CustomSection, ConfigurationErrorsException, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" allowDefinition="Everywhere" allowExeDefinition="MachineToApplication" restartOnExternalChanges="true" />
</configSections>
<appSettings>
<add key="FileName" value="FileName.csv" />
</appSettings>
<CustomSection fileName="default.txt" maxUsers="10" />
</configuration>- Marked as answer by Brian Evans Wednesday, August 10, 2011 3:33 PM
Wednesday, August 10, 2011 3:33 PM -
Check if you have the below in your App.config
<machineSettings maxTimeout="00:01:00"/>
Comment whole section. It is not required for debugging.
Wednesday, April 17, 2013 2:21 PM