[Solved] Error while saving changes to custom config file [closed]


Requirements

using System.Configuration;  

Read

var appSettings = ConfigurationManager.AppSettings;  
string result = appSettings[key] ?? "Not Found";  

Write

var configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
var settings = configFile.AppSettings.Settings;
if (settings[key] == null)
{
    settings.Add(key, value);
}
else
{
    settings[key].Value = value;
}
configFile.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection(configFile.AppSettings.SectionInformation.Name);

solved Error while saving changes to custom config file [closed]