【问题标题】:Changes in exe.config not reflecting in codeexe.config 中的更改未反映在代码中
【发布时间】:2011-12-26 18:59:38
【问题描述】:

在代码ConfigurationManager.AppSettings("IsFill") 中显示为空

但是当我手动打开 exe.config 文件时,该密钥存在于文件中

我用下面的代码修改 exe.config 文件

Dim configFile As Configuration
                    configFile = ConfigurationManager.OpenExeConfiguration(Application.ExecutablePath)
                    configFile.AppSettings.Settings("AppVersion").Value = "1.0.1"
                    configFile.Save()

ConfigurationManager.AppSettings("AppVersion") 值已更改,但当我手动打开 exe.config 时未显示更改。

表示如果你从外部修改 exe.config 文件,例如。就像你在 exe.config 中再添加一个密钥,然后当我使用下面的代码时,新密钥没有进入代码

configFile.AppSettings.Settings("AppVersion").Value
ConfigurationManager.AppSettings("AppVersion")

现在你得出结论,这两个文件都不同——我手动打开一个,另一个我用代码打开 但路径相同,我打开的是相同的文件。

【问题讨论】:

    标签: vb.net winforms app-config


    【解决方案1】:

    你可以使用

    ConfigurationManager.RefreshSection("section to refresh")
    

    【讨论】:

      【解决方案2】:

      上述错误仅出现在 windows7 操作系统中。因为 windows7 不反映 exe.config 值。 重启或注销后显示反映的值。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-09-08
        • 1970-01-01
        • 1970-01-01
        • 2019-10-16
        相关资源
        最近更新 更多