Answered by:
XML Serialisation -> "Didn't expect ..."

Question
-
An exception is thrown when I try to serialize this class: Classdiagram (in reality there are many more derived classes)
The derived classes are serializable and are only used for initialisation. (e.g. InstallAction ia = new InstallFont("somefont"))
The exception says something about the serialiser not expecting "InstallFont" (or any other derived class),
and suggests to use the attribute XmlInclude or SoapInclude.
But I'm not a big fan of these attributes... Imho the base class shouldn't know about it's derived classes.
So I tried to avoid the problem by adding a new abstract property (object[] Parameters) which is able to get and set all variables.
Then I marked all other properties with [XmlIgnore] so they won't be serialized.
But when I run this code, the same exception is still thrown...
Is there any workaround for this?
- Moved by jack 321 Thursday, July 17, 2008 6:04 AM off topic for C# general
Monday, July 14, 2008 3:54 PM
Answers
-
Discussion in Data Platform Development
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- Marked as answer by Ed Price - MSFTMicrosoft employee Friday, December 30, 2011 5:58 AM
Thursday, July 17, 2008 6:04 AM -
- Proposed as answer by Ed Price - MSFTMicrosoft employee Friday, December 30, 2011 5:59 AM
- Marked as answer by Ed Price - MSFTMicrosoft employee Friday, December 30, 2011 5:59 AM
Friday, December 30, 2011 5:59 AM
All replies
-
And something else:
I've got a class InstallItem, which is used in InstallItemCollection, which is used in InstallPage.
When I implement IEnumerable<T> in InstallItemCollection and in InstallPage, I get the following xml output:<ArrayOfArrayOfInstallItem><ArrayOfInstallItem>...</ArrayOfArrayOfInstallItem></ArrayOfInstallItem>
And all other properties aren't serialized.
(also I have to implement the non generic ICollection for at least one of both classes so the serializer won't whine about "Error cs0136")
When I delete the IEnumerable interface for InstallItemCollection, I get the following xml output:<ArrayOfInstallItemCollection><InstallItemCollection Name="test">...</InstallItemCollection><ArrayOfInstallItemCollection>
So now it serializes other properties from InstallItemCollection, but still not for InstallPage.
This is what I expect:<InstallPage Name="TestPage"><OtherProperties... /><InstallItemCollection Name="test">...</InstallItemCollection><InstallPage>
But this would mean I can't use IList<T> or any other interface implementing IEnumerable<T>.
(I'm getting really really irritated by System.Xml.Serialization...)
Monday, July 14, 2008 4:58 PM -
Discussion in Data Platform Development
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- Marked as answer by Ed Price - MSFTMicrosoft employee Friday, December 30, 2011 5:58 AM
Thursday, July 17, 2008 6:04 AM -
- Proposed as answer by Ed Price - MSFTMicrosoft employee Friday, December 30, 2011 5:59 AM
- Marked as answer by Ed Price - MSFTMicrosoft employee Friday, December 30, 2011 5:59 AM
Friday, December 30, 2011 5:59 AM