[英]Modify Custom Section in App.config
I have the following custom section in my config file: 我的配置文件中包含以下自定义部分:
<TestSettings>
<EmailAddress></EmailAddress>
</TestSettings>
I tried to modify this section on runtime with the following method: 我尝试使用以下方法在运行时修改此部分:
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
var testSettings = ConfigurationManager.GetSection("TestSettings") as NameValueCollection;
if (testSettings != null)
{
testSettings["EmailAddress"] = emailAddress;
config.Save();
ConfigurationManager.RefreshSection("TestSettings");
}
But the GetSection method returns null. 但是GetSection方法返回null。 What is the simplest way to solve this?
解决这个问题的最简单方法是什么? Thank you.
谢谢。
So you running this from a test assembly . 因此,您可以从测试程序集中运行它。 Re-read the method name:
重新读取方法名称:
ConfigurationManager.OpenExeConfiguration
Do you see it? 你看到了吗?
ConfigurationManager.Open Exe Configuration
ConfigurationManager.Open Exe配置
For a solution have a look at this answer . 如需解决方案,请查看此答案 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.