An unhandled exception of type 'System.ArgumentException' occurred in System.Private.Xml.dll: 'The node to be inserted is from a different document context

Code Example - An unhandled exception of type 'System.ArgumentException' occurred in System.Private.Xml.dll: 'The node to be inserted is from a different document context

                
                        XmlNode oNode = moDoc.CreateNode(sNodeType, sName, sNamespaceURI);

//necessary for crossing XmlDocument contexts
XmlNode importNode = oParent.OwnerDocument.ImportNode(oNode, true);

oParent.AppendChild(importNode);
return oNode;