我希望我只是缺少一些简单的东西。我需要读/写我的 exe.config 文件的一部分。我的代码中有这个:
var appConfiguration = ConfigurationManager.OpenExeConfiguration("Mytest.Console.exe");
var fileEnvironment = appConfiguration.GetSection("fileEnvironment");
这是我的 app.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="fileEnvironment" type="System.Configuration.DictionarySectionHandler"/>
</configSections>
<fileEnvironment>
<add key="TestEntry1" value="A nice value"/>
<add key="TestEntry2" value="Another value"/>
</fileEnvironment>
</configuration>
我的 appConfiguration 变量返回为 {System.Configuration.Configuration} 并且“HasFile”属性设置为 true。
不强制转换我的变量“fileEnvironment”返回为System.Configuration.DefaultSection
. 当我添加IDictionary<string, string>
到GetSection
方法 fileEnvironment 时为空。
有任何想法吗?