简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM