-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: 1.4.1
-
Component/s: None
-
None
-
Environment:All
Any user defined type that implement IEnumerable<T>, ICollection<T>, ICollection<KeyValuePair<,>>, or IDictionary<,> are incorrectly serialized.
The bug lies in the sole use of the __genericSerializerDefinitions dictionary for type resolution.
The following class hierarchy should serialize using the CollectionGenericSerializer:
interface IFooBarList<T> : IList<T>
class DummyCollection<T> : IFooBarList<T>
However the logic only calls GetGenericTypeDefinition on DummyCollection, which will not resolve against the static list of __genericSerializerDefinitions.
What needs to happen is the code should also call GetInterfaces, and traverse the generic interface definitions.
Special care needs to be taken here, because a query against some types like Dictionary<,> will return multiple candidates such as IDictionary<,>, ICollection<KeyValuePair<,>>, etc.. Precedence should always be given the the furthest derived generic interface (I.e. IDictionary<,> if no serializer is registered for Dictionary<,>.
Also, KeyValuePair<,> type should be serializable on it's own, but currently only works within the context of the DictionaryGenericSerializer. Case in point is that IDictionary<,> is really just an ICollection<KeyValuePair<,>> and they two could be decoupled.
At it's best, right now the serializer attempts to use the class map serializer and crashes.
At it's worst, the class map serializer will silently succeed in serializing nothing on a user collection, a case of silent data corruption.