Reputation: 317
Im trying to set an XMLNode
to the Clipboard using the SetData
command. I get the OutOfMemoryException
.
How can I make the XMLNode
Class serializable, or do I need to serialize every Node manually and then deserialize in the Paste function?
Copy function:
Clipboard.SetData("XmlNode", ouritem);
Paste function:
XmlNode ournode = Clipboard.GetData("XmlNode") as XmlNode;
Upvotes: 0
Views: 406
Reputation: 101680
It could be that the XmlNode
object's circular references (e.g. from the node to its parent and back) and references to all sorts of other data are causing the OutOfMemoryException.
You can place the node's XML on the clipboard as a string, and then reconstitute it later:
Clipboard.SetData("XmlNode", ouritem.OuterXml);
Paste function:
XmlDocument doc = new XmlDocument();
doc.LoadXml(Clipboard.GetData("XmlNode") as string);
XmlNode ournode = doc.DocumentElement;
Of course, one consequence of this is that this would result in an isolated node without the associations to everything else in the document that contained it.
Upvotes: 1