-
Type: Bug
-
Resolution: Duplicate
-
Priority: Unknown
-
None
-
Affects Version/s: None
-
Component/s: Serialization
Summary
We have a component that listens to events and saves all properties of the event to a mongo database. We set it up as generic as possible; all properties values are downcast to "object" so they all fit into the same model, which is stored into the database. We noticed that, as of version 2.19.0 which introduced an allowlist for the ObjectSerializer, that storing DateOnly values in a property of type object throws an exception, as the ObjectSerializer says the type is not allowed.
Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).
Version 2.19.0.
How to Reproduce
var client = new MongoClient("mongodb://localhost:27017"); var database = client.GetDatabase("test"); var collection1 = database.GetCollection<Test1>("test"); var collection2 = database.GetCollection<Test2>("test"); var instance1 = new Test1 { Value = new DateOnly(2022, 1, 1) }; var instance2 = new Test2 { Value = new DateOnly(2022, 1, 1) }; // Works await collection1.InsertOneAsync(instance1); // Crashes await collection2.InsertOneAsync(instance2); public class Test1 { public DateOnly Value { get; set; } } public class Test2 { public object Value { get; set; } }
Additional Background
Not applicable.
- duplicates
-
CSHARP-3717 Add DateOnly/TimeOnly support
- Closed