I am working in Visual Studio 2010. I have a C# project inside a solution, and an App.config in the main project directory. I'm trying to read properties in App.config from the Main()
method, as follows:
String test = ConfigurationManager.AppSettings["streamType"];
My App.config file looks like this:
<?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="InteropClient.Properties.Settings"
type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
requirePermission="false" />
</sectionGroup>
<section name="connections" type="" />
<section name="streamType" type="" />
<section name="messageClass" type="" />
<section name="serializationMethod" type="" />
<section name="encryptionMethod" type="" />
</configSections>
<connections>
<connection type="zkClient" connectionString="168.72.70.62:9181" sessionTimeout="5000" initInstructions="" name="zk1"
classes="Sodao.Zookeeper.Config.ZookeeperConfig, Zookeeper" />
<connection type="TcpClient" connectionString="" initInstructions="" />
</connections>
<streamType>MemoryStream</streamType>
<messageClass>XGenericMessage</messageClass>
<serializationMethod>Thrift</serializationMethod>
<encryptionMethod></encryptionMethod>
</configuration>
Trying to run the Main() method, the C# line above throws a ConfigurationErrorsException
that
Configuration system failed to initialize.
I'm not sure why that is. I think I've done everything in the instructions. I'd appreciate some clarity on this issue.
I believe it should look like this.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
</configSections>
**<appSettings>
<add key="streamType" value="Somevalue" />
</appSettings>**
</configuration>
With your AppSettings node being outside the configSections.