Problem:
I have a program where i write Keys+Values in my appconfig during runtime, but when i want to read them i get the old values and the only way to get the new values is by restarting the application.
As soon as i write the key+value programmically the config file is updated so that is not the problem, but i cannot figure out why i wont get the new values during the same runtime.
I write like this: (tried with and without RefreshSection(key) - made no difference)
public static void AddValue(string key, string value)
{
Configuration config = ConfigurationManager.OpenExeConfiguration(System.Reflection.Assembly.GetEntryAssembly().Location);
config.AppSettings.Settings.Add(key, value);
config.Save(ConfigurationSaveMode.Full);
ConfigurationManager.RefreshSection(key);
}
And i read it like this:
string[] ItemsArray = ConfigurationManager.AppSettings["Items"].Split(',');
Question:
How can i read the new keys (in runtime) which i added during the same runtime?