title: How to Save to Roaming Profile using ConfigurationManager in C#
body: <p>I'm trying to save a string to the AppSettingsSection of the current application's default configuration in the roaming profile using ConfigurationManager (ConfigurationUserLevel.PerUserRoaming).</p>
  
  <p>When I'm saving to the local profile (ConfigurationUserLevel.None) it works just fine.</p>
  
  <pre><code>// Write Name in NameSaved Section of AppSettings
  public void WriteNameToAppSettings(string nameToSave)
  {
      // Open Config File
      Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoaming); // ConfigurationUserLevel.None (local) is working just fine...
  
      // Add or Update NameSaved Section of AppSettings
      if ((configuration.AppSettings.Settings["NameSaved"]?.Value) == null)
          configuration.AppSettings.Settings.Add("NameSaved", nameToSave);
      else
          configuration.AppSettings.Settings["NameSaved"].Value = nameToSave;
  
      //  Save and Refresh Config File            
      configuration.Save(ConfigurationSaveMode.Modified);
      ConfigurationManager.RefreshSection(configuration.AppSettings.SectionInformation.Name);
  }
  
  // Set LastEnteredName Property from NameSaved Section of AppSettings
  public void ReadNameFromAppSettings()
  {
      // Read Config File and then Get Name LastEntered Section of AppSettings
      LastEnteredName = ConfigurationManager.AppSettings["NameSaved"]?.ToString() ?? ""; // If null default to ""
  }
  </code></pre>
  
  <p>The error I'm getting is:<br>
  System.InvalidOperationException: 'ConfigurationSection properties cannot be edited when locked.'</p>
  
  <p>Any clues on how to fix this?</p>