2012-01-28, 07:01 PM
Right, time to get to the bottom of this bugger. I've seen this error with a couple of my plugins now, but seeing as they were all written in the same way that's hardly surprising 
Here's the first block of code that runs when the System plugin saves its settings (after clicking ok in the Settings dialog):
"System.ArgumentException: The node to be inserted is from a different document context", "at System.Xml.XmlNode.AppendChild(XmlNode newChild)" is thrown - very very rarely - when it hits that last line of code. Why?
If it was wrong, surely it would crap-out every time :confused:
Testing fixes is difficult because it's so rare. If I open/ok, open/ok, etc the Settings dialog enough times I can usually force it, but I'd love to get rid of it for good!
Iain

Here's the first block of code that runs when the System plugin saves its settings (after clicking ok in the Settings dialog):
Code:
string path = "/Settings/PluginSettings/System";
SettingsHelper sh = SettingsHelper.GetInstance();
XmlDocument doc = sh.GetBackingDocument();
XmlNode system = sh.GetSettingsNode(path);
// Clear the current <System> node (if it exists)
if (system != null)
system.RemoveAll();
// Otherwise, create it
else
{
system = doc.CreateElement("System");
sh.GetSettingsNode("/Settings/PluginSettings").AppendChild(system);
}
//Now (re)fill it with data
system.AppendChild(doc.CreateElement("ConfirmShutdownMode"));
// More similar lines follow...
...
"System.ArgumentException: The node to be inserted is from a different document context", "at System.Xml.XmlNode.AppendChild(XmlNode newChild)" is thrown - very very rarely - when it hits that last line of code. Why?
If it was wrong, surely it would crap-out every time :confused:
Testing fixes is difficult because it's so rare. If I open/ok, open/ok, etc the Settings dialog enough times I can usually force it, but I'd love to get rid of it for good!
Iain