EDN Admin
Well-known member
HI all;
Here is what i have. I have a base class (BaseObject) and three classes derived from it (First, Second, Third). I have a collection object (Collections) derived from ICollections that contains a List<BaseObjects>. When i use the XmlSerializer to stream
this collection to a file i get the following error:
"The type TestXML.First was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically."
I have added the following lines to both the Collections class and the BaseObjects class:
<span style="font-size:small <span style="font-size:small
<pre class="prettyprint [XmlInclude(typeof(First))]
[XmlInclude(typeof(Second))]
[XmlInclude(typeof(Third))][/code]
I even use the list of class types the XmlSerializer collection: xmlWriter = new XmlSerializer(aType, aTypeList);<br/>
I used to do something similar using the the BinaryFormatter and an interface instead of a base class. Now i need the generated file to be readable as text so i cant use the BinaryFormatter and the SoapFormatter seemes to have the same problems as the XmlSerializer.
What could i be missing? Is there something else i should try?
<hr class="sig Shawn
View the full article
Here is what i have. I have a base class (BaseObject) and three classes derived from it (First, Second, Third). I have a collection object (Collections) derived from ICollections that contains a List<BaseObjects>. When i use the XmlSerializer to stream
this collection to a file i get the following error:
"The type TestXML.First was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically."
I have added the following lines to both the Collections class and the BaseObjects class:
<span style="font-size:small <span style="font-size:small
<pre class="prettyprint [XmlInclude(typeof(First))]
[XmlInclude(typeof(Second))]
[XmlInclude(typeof(Third))][/code]
I even use the list of class types the XmlSerializer collection: xmlWriter = new XmlSerializer(aType, aTypeList);<br/>
I used to do something similar using the the BinaryFormatter and an interface instead of a base class. Now i need the generated file to be readable as text so i cant use the BinaryFormatter and the SoapFormatter seemes to have the same problems as the XmlSerializer.
What could i be missing? Is there something else i should try?
<hr class="sig Shawn
View the full article