title: How do I save a configuration file with a custom configuration section?
body: <p>I have an application that at run-time needs to insert a custom section into its app/web.config.  Normally this can be accomplished with something like:</p>
  
  <pre><code>var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
  var mySection = new MyCustomSection { SomeProperty="foo" };
  
  config.Sections.Add("mySection", mySection);
  section.SectionInformation.ForceSave = true;
  config.Save(ConfigurationSaveMode.Full);
  </code></pre>
  
  <p>The problem I'm running into here is that the section I'm adding to the configuration file needs its own serialization handler.  I know this can easily be handled when <em>reading</em> the configuration by simply creating an implementation of IConfigurationSectionHandler, but I can't seem to find a way to actually <em>write</em> the configuration section itself.</p>
  
  <p>Looking at the <a href="https://msdn.microsoft.com/en-us/library/system.configuration.configurationsection_methods(v=vs.110).aspx" rel="nofollow">MSDN</a>  documentation the ConfigurationSection class does have a SerializeSection/DeserializeSection method, but they're marked internal and cannot be overridden.  I also found a GetRawXml/SetRawXml method in SectionInformation, but they're marked as infrastructure-level calls that shouldn't be invoked directly by user code.</p>
  
  <p>Is what I'm trying to do even possible?  It seems like a pretty straight-forward use case.</p>
  
  <p>Thanks.</p>