Details
-
Bug
-
Resolution: Works as Designed
-
Major - P3
-
None
-
2.10.2
-
None
Description
The issue CSHARP-1521 occurs again in the newest 2.10.2 C# Driver. Error message:
The serializer for field 'MyDictionary' must implement IBsonArraySerializer and provide item serialization info.
|
Model is definied like this:
public class Model |
{
|
public Dictionary<long, Guid> MyDictionary { get; set; } |
}
|
ClassMap is registered as below:
BsonClassMap.RegisterClassMap<Model>(cm =>
|
{
|
cm.AutoMap();
|
cm.MapProperty(c => c.MyDictionary).SetSerializer(new DictionaryInterfaceImplementerSerializer<Dictionary<long, Guid>>(DictionaryRepresentation.ArrayOfDocuments)); |
});
|
My query:
Builders<Model>.Filter.ElemMatch(request => request.MyDictionary, f => f.Value.Equals(value));
|
And I have a workaround that works for me, but I don't want to use it in long term:
public class DictionaryArrayInterfaceImplementerSerializer<TDictionary, TKey, TValue> : DictionaryInterfaceImplementerSerializer<TDictionary>, IBsonArraySerializer where TDictionary : class, IDictionary, new() |
{
|
public DictionaryArrayInterfaceImplementerSerializer(DictionaryRepresentation dictionaryRepresentation) : base(dictionaryRepresentation) |
{ } public bool TryGetItemSerializationInfo(out BsonSerializationInfo serializationInfo) |
{
|
var serializer = new KeyValuePairSerializer<TKey, TValue>(); |
serializationInfo = new BsonSerializationInfo( |
null, |
serializer,
|
serializer.ValueType); return true; |
}
|
}
|
Basically I can create new serializer, which inherits from DictionaryInterfaceImplementerSerializer, but also implements IBsonArraySerializer and then everything works.
Attachments
Issue Links
- is related to
-
CSHARP-1521 ElemMatch requires IBsonArraySerializer for DictionaryInterfaceImplementerSerializer
-
- Closed
-
- related to
-
CSHARP-3010 Add a clear error when a serializer for dictionary classes is configured incorrectly
-
- Backlog
-