Deserializing multiple different derived types

intensecool

New Member
Running into a bit of an issue here. I have some xml that is coming back from a 3rd party service that looks like this(simplified)\[code\]<Root> <Response> <Record></Record> </Response> <Response> <Record></Record> </Response></Root>\[/code\]Each record has the potential to be an object of a different type, and a single xml message could have multiple responsesMy classes look something like this\[code\]public class Response{ [XmlElement(typeof(DerivedRecord1))] [XmlElement(typeof(DerivedRecord2))] public BaseRecord Record { get; set;}}public class BaseRecord { }public class DerivedRecord1 : BaseRecord { }public class DerivedRecord2 : BaseRecord { }\[/code\]When I look at the Record object after it has been deserialized, it comes back as null for both responses.Now, when I use the XmlInclude element on my base class instead the XmlElement attribute on the property, the Record is of the base class and not the derived type. What am I doing wrong here?
 
Back
Top