title: Change app.config at runtime - in memory - not working "Access denied"
body: <pre><code>    var configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
      if (configuration.AppSettings.Settings[key] == null)
      {
          configuration.AppSettings.Settings.Add(new KeyValueConfigurationElement(key, value));
      }
      else
      {
          configuration.AppSettings.Settings[key].Value = value;
      }
      configuration.Save(ConfigurationSaveMode.Modified);
      ConfigurationManager.RefreshSection(&quot;appSettings&quot;);
  </code></pre>
  <p>I've read all stackoverflow related questions and the answers are: You can't write to app.config file at run time. Which is fine for me. But I also found accepted answers that said you can change the in-memory app.config with the above code.
  But I get the same error that the file is read-only... even though this code is supposed to only change in-memory?</p>
  <p>What am I missing?</p>
  <p>I am using .net framework 4.7.2.</p>