Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-460

User types that implement generic collection interfaces are incorrectly serialized.

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 1.5
    • Affects Version/s: 1.4.1
    • Component/s: None
    • Labels:
      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.

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            optimiz3 Alexander Nagy
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: