User1587670440 posted
I am currently working on creating new config files with custom settings. I have no problem calling the config.saveAs(path) the first time, but the same function will throw this exception when being called the second time:
"System.Configuration.ConfigurationErrorsException: 'The configuration file has been changed by another program."
I dont understand why this exception is thrown because "ConfigurationManager.RefreshSection(sectionName);" is called on the next line.Here is some code:
string sectionName = "Recipe_Config";
string path = @"Recipe.config";
string newPath1 = @"Recipe1.config";
string newPath2 = @"Recipe2.config";
ConfigurationFileMap map = new ConfigurationFileMap(path);
Configuration config = ConfigurationManager.OpenMappedMachineConfiguration(map);
config.SaveAs(newPath1);
ConfigurationManager.RefreshSection(sectionName);
config.SaveAs(newPath2); //exception here
ConfigurationManager.RefreshSection(sectionName);
Console.WriteLine("..save as done");
Console.ReadLine();
Thanks
Lew