我在Visual Studio 2010中工作。我在解决方案中有一个C#项目,并在主项目目录中有一个App.config。我试图从Main()
方法App.config中读取属性,如下所示:读取C#项目中的App.config元素
String test = ConfigurationManager.AppSettings["streamType"];
我App.config文件看起来是这样的:
<?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>
尝试运行的Main()方法,上面的C#行会抛出ConfigurationErrorsException
配置系统初始化失败。
我不确定这是为什么。我想我已经在指示中做了所有事情。我很感谢在这个问题上的一些澄清。
谢谢,明白了。 –