Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>UPDATE</strong></p> <p>The solution below did not work because XmlDocument does not dispose and it seems some versions of .net do not close correctly when given a file path. The solution (example code in the link) is to open a stream which will do a dispose and pass that stream to the save function.</p> <p>A solution is shown here. <a href="http://web-beta.archive.org/web/20150107004558/www.devnewsgroups.net/group/microsoft.public.dotnet.xml/topic40736.aspx" rel="nofollow noreferrer">http://web-beta.archive.org/web/20150107004558/www.devnewsgroups.net/group/microsoft.public.dotnet.xml/topic40736.aspx</a></p> <hr> <p><em>Old stuff below</em></p> <p>Try this: </p> <p>Note, I changed to xpath, but it has been a while so I might have gotten the xpath wrong, but in any case you should use xpath and not walk the tree. As you can see it is much clearer.</p> <p>The important point is the <code>using</code> statement which will <code>dispose()</code>, which I think was your problem.</p> <p>Let me know, good luck.</p> <pre><code> public void UpdateAppSettings(string key, string value) { using (XmlDocument xmlDoc = new XmlDocument()) { xmlDoc.Load(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile); xmlDoc.DocumentElement.FirstChild.SelectSingleNode("descendant::"+key).Attributes[0].Value = value; xmlDoc.Save(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile); } System.Configuration.ConfigurationManager.RefreshSection("section/subSection"); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload