Problem saving .NET configuration class

When I change a configuration property and call the Save () method on the configuration object, and then change the config property and call Save () again, I get an exception because the config has been changed.

Exception text: "The configuration file was changed by another program."

So, if the user changes and saves something at runtime, but changes something, and saving my application will throw an exception. I'm right?

Is it possible to save the configuration several times?

EDIT: Provided sample code.

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 included the Config property in my section to use it to save the configuration as follows.

 mySection.Config.Save(); 
+4
source share
1 answer

The documentation states: "If the configuration file has changed since the creation of this configuration object, a runtime error occurs." Therefore, after Save() you need to destroy the configuration object and recreate it for several save operations in order to work properly.

+6
source

All Articles