小编Ale*_*nes的帖子

如何重新加载/刷新app.config?

我想读取app.config值,在消息框中显示它,使用外部文本编辑器更改值,最后显示更新的值.

我尝试使用以下代码:

private void button2_Click(object sender, EventArgs e)
{
    Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
    ConfigurationManager.RefreshSection("appSettings");
    ConfigurationManager.RefreshSection(config.AppSettings.SectionInformation.Name);
    MessageBox.Show(ConfigurationManager.AppSettings["TheValue"]);
}
Run Code Online (Sandbox Code Playgroud)

但它不起作用.它显示旧值(在外部文本编辑器中更改之前).有什么建议?

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
  <add key="TheValue" value="abc"/>
</appSettings>
</configuration>
Run Code Online (Sandbox Code Playgroud)

.net c# app-config config

9
推荐指数
2
解决办法
2万
查看次数

标签 统计

.net ×1

app-config ×1

c# ×1

config ×1