我想在运行时从/向C#项目app.config文件读取/写入设置信息。 以下尝试失败:
var s = ConfigurationManager.AppSettings["mySet"];
s为空var sect = ConfigurationManager.GetSection("testing.Properties.Settings") as AppSettingsSection;
sect为null 下面是App.config文件内部视图:
configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="testing.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<userSettings>
<testing.Properties.Settings>
<setting name="mySet" serializeAs="String">
<value>a</value>
</setting>
<setting name="hisSet" serializeAs="String">
<value>b</value>
</setting>
</testing.Properties.Settings>
</userSettings>
但是,我可以通过以下电话阅读此信息:
var prop = Properties.Settings.Default.mySet;
为什么使用ConfigurationManager类的代码会失败?
PS。我将testing.exe.config存储在与testing.exe相同的目录下