I have been able to get simple circular references to be serialized in xml
by using the ImportTypeMapping method on the SoapReflectionImporter class.
But I am unable to serialise circular references when the circular reference
is contained with in a collection class, specifically I am using a custom
ArrayList object. I keep getting a StackOverFlow Exception from the
XmlSerializer class when attempting the serialisation.
The classes are:
Class A,
Class B - this is derived from System.Collection.ArrayList
Class C.
Class A contains an instance of B
Class B contains multiple instances of C
Class C contains a reference to A
So in C# Code an example would be:
// Create parent object
A a = new A();
// Create container to hold children
B b = new B();
// Create children
C c1 = new C();
C c2 = new C();
C c3 = new C();
// Set the parent nodes for these children
c1.A = a;
c2.A = a;
c3.A = a;
// Assign the container to the parent
a.B = b;
// Add the children
b.Add(c1);
b.Add(c2);
b.Add(c3);
XmlTextWriter tw = new XMLTextWriter(Console.Out);
tw.WriteStartElement("Root");
XMLSerializer ser = new XmlSerializer(new
SoapReflectionImporter().ImportTypeMapping(typeof( A)));
ser.Serialize(tw, a);
tw.Close();
Cheers in advance
Ollie