[CSHARP-3010] Add a clear error when a serializer for dictionary classes is configured incorrectly Created: 12/Mar/20  Updated: 31/Mar/22

Status: Backlog
Project: C# Driver
Component/s: Error Handling, Serialization
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Minor - P4
Reporter: Dmitry Lukyanov (Inactive) Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to CSHARP-2991 Regression of CSHARP-1521. ElemMatch ... Closed

 Description   

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>.


Generated at Wed Feb 07 21:44:07 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.