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?
Add the
XmlIncludeattribute to the Person class, to make the XmlSerializer aware of the PersonI2 class :