title: Trouble writing to App.Config file
body: <p>Having issues reading/writing to App.config.</p>
  
  <p>The code I have below I took from the MSDN article on (AppSettingsSection Class) 
  <a href="http://msdn.microsoft.com/en-us/library/system.configuration.appsettingssection%28v=vs.100%29.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/system.configuration.appsettingssection%28v=vs.100%29.aspx</a></p>
  
  <p>I am successfully able to read the App.config file and get/use the values and it responds correctly if I change the App.config file to get the new values.</p>
  
  <p>However, in this (from MS page) I add a new entry and change a value on one of my initial entries.  It appears to change it, does not error in saving it, but does not write it to the file so the next time I run, I am back to my initial values in App.config.</p>
  
  <p>Can someone show me my erroneous ways?</p>
  
  <p>TIA!</p>
  
  <pre><code>Imports System
  Imports System.Collections.Specialized
  Imports System.Configuration
  Imports System.Text
  Imports System.IO
  
  ' IMPORTANT: To compile this example, you must add to the project 
  ' a reference to the System.Configuration assembly.
  '
  Module Module1
      Sub Main()
          Dim KeypairHolder As String = Nothing
          ' Get Configuration File as config object
          Dim config As System.Configuration.Configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
  
          ' Create a unique key/value pair to add to the appSettings section.
          Dim keyName As String = "DateTimeStamp Number " &amp; config.AppSettings.Settings.Count + 1
          Dim value As String = String.Concat(Date.Now.ToLongDateString(), " ", Date.Now.ToLongTimeString())
  
          ' Create appSettings as object
          Dim appSettings As System.Configuration.AppSettingsSection = config.AppSettings
  
          ' add the new key and value 
          appSettings.Settings.Add(keyName, value)
  
          ' save and refresh the values
          config.Save(ConfigurationSaveMode.Modified)
  
          ' Force a reload in memory of the changed section.
          ConfigurationManager.RefreshSection("appSettings")
  
          ' Get keys
          Dim kAll() As String = appSettings.Settings.AllKeys()
  
          ' Build string to display
          For Each key In kAll
              KeypairHolder = KeypairHolder &amp; key &amp; ":  " &amp; appSettings.Settings(key).Value &amp; vbCrLf
          Next
  
          'Display
          MsgBox(KeypairHolder)
  
          ' Change a value
          appSettings.Settings("CustomKey").Value = "Changed Value"
  
          ' Resave and get and display
          config.Save(ConfigurationSaveMode.Modified)
          ConfigurationManager.RefreshSection("appSettings")
          kAll = appSettings.Settings.AllKeys()
          KeypairHolder = Nothing
          For Each key In kAll
              KeypairHolder = KeypairHolder &amp; key &amp; ":  " &amp; appSettings.Settings(key).Value &amp; vbCrLf
          Next
          MsgBox(KeypairHolder)
  
      End Sub
  End Module
  
  ' appSettings Section of my App.Config file
  '   &lt;appSettings&gt;
  '    &lt;add key="UsernamePassword" value="BobsUsername:BobsPassword"/&gt;
  '    &lt;add key="CustomKey" value="ConfigApp Value"/&gt;
  '  &lt;/appSettings&gt;
  </code></pre>