title: C# update app.config element
body: <p>I have a WCF server which has the following app.config file:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;configuration&gt;   
    &lt;system.serviceModel&gt;   
      &lt;services&gt;
        &lt;service name="MyService" behaviorConfiguration="DiscoveryBehavior"&gt;       
          &lt;endpoint address="net.tcp://192.168.150.130:44424/ServerService/"/&gt;        
          &lt;endpoint name="udpDiscovery" kind="udpDiscoveryEndpoint"/&gt;
        &lt;/service&gt;
      &lt;/services&gt;
    &lt;/system.serviceModel&gt; 
  &lt;/configuration&gt;
  </code></pre>
  
  <p>At installation on a different machine, I want to make it to update automatically the address with the address of that machine. I have the string but I don't understand how to update the "address" item in the app.config file. I have the following code but this does not work:</p>
  
  <pre><code>var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); 
  config.AppSettings.Settings["address"].Value = "new_value";
  config.Save(ConfigurationSaveMode.Modified);
  ConfigurationManager.RefreshSection("appSettings"); 
  </code></pre>
  
  <p>I guess it is not working because I do not have the section named "appSettings", but how to access that "address" item ? I tried different solutions, but nothing works.</p>
  
  <p>Thank you in advance.</p>