XML Serializing an Object that Inherits a List of itself
-
I have an object, called Tag, which inherits List<Tag>. This works great code wise, I can add objects of type tag to my tag without issue. But when I try to serialize the object to XML it crashes with a "An unhandled exception of type 'System.StackOverflowException' occurred in System.Xml.dll" error when I try to initialize a new instances the XmlSerializer class, and pass in the type of Tag. If I remove the Inherts List<Tag> and just create a new property of type List<Tag> instead, then this serializes great, but does not give me quite the appearance I want. Is there someway to make this work without custom serialization, or maybe only minor custom serialization? Thanks, Peter
-
I have an object, called Tag, which inherits List<Tag>. This works great code wise, I can add objects of type tag to my tag without issue. But when I try to serialize the object to XML it crashes with a "An unhandled exception of type 'System.StackOverflowException' occurred in System.Xml.dll" error when I try to initialize a new instances the XmlSerializer class, and pass in the type of Tag. If I remove the Inherts List<Tag> and just create a new property of type List<Tag> instead, then this serializes great, but does not give me quite the appearance I want. Is there someway to make this work without custom serialization, or maybe only minor custom serialization? Thanks, Peter