XmlSerializer
is calling IList
on my class and I don\'t understand why.
I have a custom class (one of several classes in a h
Without a good, minimal, complete code example that reliably reproduces the problem, it will be impossible to provide any specific answer.
In lieu of that, here are some non-specific notes that may help you:
IEnumerable
interface (e.g. IList
) is considered a collection. Such types are serialized by enumerating the collection and storing the individual elements. On deserialization, .NET assumes it can use an Add()
method to populate the deserialized object. Woe unto any type that throws an exception from the Add()
method or, worse, doesn't implement one at all.[DataContract]
attribute. This overrides the default behavior, allowing your type to be treated as a non-collection type.IList
in the first place, but instead should have exposed the enumeration of elements differently, e.g. as a property that returns the enumeration. Lacking a good code example (well, any code example) it's not possible to say whether this is true in your scenario or not, but I'd say there's at least a 50/50 chance it is.