Greens
Greens

Reputation: 3057

How do I Serialize and DeSerialize all properties to String using Mongo C# Driver's BSONClassMap

BsonClassMap.RegisterClassMap<X>(cm => { cm.AutoMap(); cm.GetMemberMap(x => x.date).SetSerializer(new dateSerializer());

        });

I am getting an error that item already contains a key and if I remove the serializer , I get the error ReadBsonType can only be called when state is Type and not when state is Value"

How do I debug this?

Upvotes: 0

Views: 744

Answers (1)

Craig Wilson
Craig Wilson

Reputation: 12624

You likely have two problems.

1) Item already contains a key. You need to make sure that class map registration occurs before any communication with the server occurs. This error is likely caused by serialization taking place for X before this RegisterClassMap is called. If you are sure this isn't true, a stack trace would be helpful.

2) Your implementation of dateSerializer is likely incorrect. If you could post your implementation, we'd be able to help debug it. Probably warrants a separate question.

Upvotes: 1

Related Questions