Have a class with a public property named "TheFirstPropertyOfArrayListType"
of type ArrayList, property has attribute XmlElement to describe the
contents of the ArrayList, the contents is a public class with attribute
XmlSerializable.
This "second level" class named "SecondClass" has an attribute of type
XmlSerializable, a public property of type ArrayList, with attribute
XmlElement to describe the contents of the ArrayList, the contents is a
public class (ThirdClass, se below) with attribute XmlSerializable.
This "third level class named "ThirdClass" has three public properties of
simple types (string, string and bool).
Both the SecondClass and the ThirdClass har default constructors and they
inherit from object only
When I try to serialize the property (see first line in this post) with:
:
XmlSerializer serializer = new
XmlSerializer(TheFirstPropertyOfArrayListType.GetT ype());
XmlTextWriter xmlWriter = new XmlTextWriter("test.xml", Encoding.UTF8);
serializer.Serialize(xmlWriter, TheFirstPropertyOfArrayListType);
xnlWriter.Close();
When this is executed an exception of type
'System.InvalidOperationException' occurred in system.xml.dll
This is thrown in the Serialize method.
Message: Additional information: The type Second was not expected. Use
XmlInclude or SoapInclude to specify types that are not known statically.
Class Second is not created by Reflection so it should be known "statically"
(??)
can anyone tell me what is wrong ? Is it not possible to serialize an
ArrayList containing other ArrayLists containing a class ?