none
ConfigurationManager.RefreshSection works for a Windows Form, but not for its parent C# Console Application RRS feed

  • Question

  • EDIT: Nevermind, I had an error at the logic of the reading it at the console. You can close the thread to not confuse anyone as it being an on topic reason.

    This is odd behavior that I can't figure out.

    I start a Form with ShowDialog() from a console application (which suspends the console application thread) in  which I loop through ConfigurationManager.AppSettings[] and then edit them with 

    var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);        
    
    config.AppSettings.Settings[pair[0]].Value = pair[1];
    config.Save(ConfigurationSaveMode.Modified);                
    
    ConfigurationManager.RefreshSection(config.AppSettings.SectionInformation.Name);

    This does seem to work properly to re-read the config from the Form (with a future loop through ConfigurationManager.AppSettings[]) but not from the console application.

    If I attempt to read ConfigurationManager.AppSettings[] from the console application (instead of the Form) - after the Form is closed - the values returned are the initial unchanged ones.

    If the software is restarted in whole, the settings are re-read properly from both console and Form so the .config is physically saved.

    PS. If I do add a RefreshSection() to the console before reading, it doesn't change the behavior either.


    • Edited by j riv Friday, June 15, 2018 8:37 AM
    Friday, June 15, 2018 7:00 AM

Answers

  • Nevermind, I had an error at the logic of the reading it at the console. You can close the thread to not confuse anyone as it being an on topic reason.
    • Marked as answer by j riv Friday, June 15, 2018 8:37 AM
    Friday, June 15, 2018 8:37 AM

All replies

  • OP here. My best current assumption is that console and form have two entirely different copies (instances) of the structure but I can't easily google a reference to such a thing.
    Friday, June 15, 2018 8:03 AM
  • Nevermind, I had an error at the logic of the reading it at the console. You can close the thread to not confuse anyone as it being an on topic reason.
    • Marked as answer by j riv Friday, June 15, 2018 8:37 AM
    Friday, June 15, 2018 8:37 AM