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

Add a clear error when a serializer for dictionary classes is configured incorrectly

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Labels:
      None

      This ticket is a continuation of the ticket CSHARP-2991.
      Now users can configure serialization in this way:

       BsonClassMap.RegisterClassMap<Model>(cm =>
       {
           cm.AutoMap();
           cm.MapProperty(c => c.MyDictionary) // MyDictionary is Dictionary<TKey,TValue>
      	   .SetSerializer(
      		new DictionaryInterfaceImplementerSerializer<Dictionary<long, Guid>>(
      			DictionaryRepresentation.ArrayOfDocuments));
       });
      

      This DictionaryInterfaceImplementerSerializer<TDictionary> using is wrong here since this way is designed to work only with non generic types, like Hashtable and not with Dictionary<TKey,TValue> itself. But this configuration will not trigger any errors and we will see error only in serialization steps which will be not really userfriendly and helpful.

      It will be more userfriendly to have a clear error message when they configure custom serialization with DictionaryInterfaceImplementerSerializer before actual deserialization steps.

      The message can be like:

      For dictionary classes that implement IDictionary<TKey, TValue> use DictionaryInterfaceImplementerSerializer<TDictionary, TKey, TValue> instead of DictionaryInterfaceImplementerSerializer<TDictionary>.
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            dmitry.lukyanov@mongodb.com Dmitry Lukyanov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: