开发者

.NET Configuration Class save problem

When I change some config property and call Save() method to configuration object, and then change some config property and call Save() again I get exception because config was changed.

Text of exception: "The configuration file has been changed by another program."

So if user in run time changes something and do save and than changes something again and do save my app will throw exception. Am I right?

Shouldn't I be able to save config multiple times?

EDIT: Provided code sample.

ExeConfigurationFileMap map = new ExeConfigurationFileMap();
            map.LocalUserConfigFilename = UserConfig;
            map.RoamingUserConfigFilename = RoamingConfig;
            map.ExeConfigFilename = AppConfig;

            System.Configuration.Configuration combinedConfigFile = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.PerUserRoamingAndLocal);

     开发者_如何转开发       AddinConfiguration combinedConfig = (AddinConfiguration)combinedConfigFile.GetSection(sectionName);
            combinedConfig.Config = combinedConfigFile;
            return combinedConfig;

I have injected property Config into my section so I can use it to save configuration like this.

mySection.Config.Save();


The documentation states: "If the configuration file has changed since this Configuration object was created, a run-time error occurs." So after Save(), you need to destroy the configuration object and recreate it for multiple save operations to work normally.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜