【发布时间】:2012-05-26 05:33:21
【问题描述】:
我有一个如下所示的 app.config 文件:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="TestKey" value="TestValue" />
</appSettings>
<newSection>
</newSection>
</configuration>
我正在尝试以这种方式使用它:
System.Configuration.ConfigurationFileMap fileMap = new ConfigurationFileMap(@"C:\app.config");
System.Configuration.Configuration configuration = System.Configuration.ConfigurationManager.OpenMappedMachineConfiguration(fileMap);
但是,它似乎不起作用。当我在读入文件后立即中断和调试时,我尝试查看configuration.AppSettings,我得到一个'configuration.AppSettings' threw an exception of type 'System.InvalidCastException'。
我确定我正在阅读该文件,因为当我查看 configuration.Sections["newSection"] 时,我返回一个空的 {System.Configuration.DefaultSection}(而不是 null)。
我猜我有一些非常基本的错误...AppSettings 发生了什么?
【问题讨论】:
标签: .net app-config