C# 带日期时间的bsondatetime选项?

C# 带日期时间的bsondatetime选项?,c#,mongodb,C#,Mongodb,我通过c#遇到了mongodb的问题 当我尝试将对象保存到mongodb时,出现以下错误: System.NotSupportedException: 'A serializer of type 'StringSerializer' is not configurable using an attribute of type 'BsonDateTimeOptionsAttribute'.' 这是导致问题的属性: [BsonDateTimeOptions(Kind = DateTime

我通过c#遇到了mongodb的问题

当我尝试将对象保存到mongodb时,出现以下错误:

System.NotSupportedException: 'A serializer of type 'StringSerializer' is 
not configurable using an attribute of type 'BsonDateTimeOptionsAttribute'.'
这是导致问题的属性:

    [BsonDateTimeOptions(Kind = DateTimeKind.Unspecified)]
    public DateTime? StartDate { get; set; }
问题在于它是一个可空的DateTime属性

为了使序列化正常工作,我可以做些什么


谢谢

所以我发现了问题,问题不在于StartDate字段,而在于另一个string类型的字段,我没有注意到我标记为BsonDateTimeOptions,因此Bson序列化程序尝试将字符串序列化为DateTime