[英]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());
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" 我收到一条错误消息,即该项目已经包含一个密钥,并且如果我删除了序列化程序,我将收到错误ReadBsonType,该错误只能在state为Type时调用,而在state为Value时不能调用。
How do I debug this? 我该如何调试?
You likely have two problems. 您可能有两个问题。
1) Item already contains a key. 1)项目已经包含一个密钥。 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.
此错误很可能是由在调用此RegisterClassMap之前X发生的序列化引起的。 If you are sure this isn't true, a stack trace would be helpful.
如果您确定这不是真的,那么堆栈跟踪会有所帮助。
2) Your implementation of dateSerializer is likely incorrect. 2)您实现的dateSerializer可能不正确。 If you could post your implementation, we'd be able to help debug it.
如果您可以发布实施,我们将能够帮助对其进行调试。 Probably warrants a separate question.
可能需要一个单独的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.