title: Modifying app.config at runtime throws exception
body: <p>I'm using <code>app.config</code> file to store and read some parameters (sql server instance name, user, password, log directory, etc). Now, I need to modify some parameters which depends of user and managed this but only if I run <code>.exe</code> from bin/release directory.</p>
  
  <p>When I create setup and install my aplication I'm not able to change this parameters - it throws <code>TargetInvocationException</code>. I've tried to run my app as administrator but without success.</p>
  
  <p>The code which I currently use is the following:</p>
  
  <pre><code>System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
  config.AppSettings.Settings.Remove("username");
  config.AppSettings.Settings.Add("username", this.Config.Username);
  config.Save(ConfigurationSaveMode.Modified);
  ConfigurationManager.RefreshSection("appSettings");
  </code></pre>
  
  <p>I've tried a few other solutions found on stackoverflow but without success.</p>