Unknown attribute xsi:type in XmlSerializer

Posted by vanccoon on Stack Overflow See other posts from Stack Overflow or by vanccoon
Published on 2010-04-30T22:54:50Z Indexed on 2010/04/30 22:57 UTC
Read the original article Hit count: 254

Filed under:

I am learning XML Serialization and meet an issue, I have two claess

[System.Xml.Serialization.XmlInclude(typeof(SubClass))] public class BaseClass {

}

public class SubClass : BaseClass { }

I am trying to serialize a SubClass object into XML file, I use blow code

XmlSerializer xs = new XmlSerializer(typeof(Base)); xs.Serialize(fs, SubClassObject);

I noticed Serialization succeed, but the XML file is kind of like

...

If I use

XmlSerializer xs = new XmlSerializer(typeof(Base)); SubClassObject = xs.Deserialize(fs) as SubClass;

I noticed it will complain xsi:type is unknown attribute(I registered an event), although all information embedded in the XML was parsed successfully and members in SubClassObject was restored correctly.

Anyone has any idea why there is error in parsing xsi:type and anything I did wrong?

Thanks

© Stack Overflow or respective owner

Related posts about c#