Reputation: 29993
Here's an example program showing what I'm trying to do:
The XML in the 'xml' string describes a list of items. The PersonI2 type should be considered as extending the Person type, and therefore I want the XmlSerializer to deserialize the PersonI2 entries in the XML as PersonI2 objects... instead, the XmlSerializer throws an exception. Why, and how can I fix it?
Upvotes: 0
Views: 2089
Reputation: 292425
Add the XmlInclude
attribute to the Person class, to make the XmlSerializer aware of the PersonI2 class :
[XmlType(AnonymousType = true, TypeName = "Person", Namespace = "")]
[XmlInclude(typeof(PersonI2))]
public class Person {
...
Upvotes: 2