-
Type: Bug
-
Resolution: Duplicate
-
Priority: Unknown
-
None
-
Affects Version/s: 2.19.0
-
Component/s: Serialization
-
None
Hi
We're having problems with the `ObjectSerializer` for the MongoDB.Driver.Core driver version `2.19.0`.
We're storing "fingerprints" of objects where we use dynamic to save the properties used to calculate what we call a "fingerprint"-hash.
We have the following class
```c#
public class Fingerprint
{
[BsonElement("id"), BsonId, BsonIgnoreIfDefault, BsonRepresentation(BsonType.ObjectId)]
public string Id
[BsonElement("createdAt"), BsonDateTimeOptions(Kind = DateTimeKind.Utc)]
public DateTime CreatedAt { get; set; }
= DateTime.Now;
[BsonElement("hash")]
public string Hash
[BsonElement("data")]
public object Data { get; set; }
[BsonElement("metadata")]
public object Metadata
}
```
We're then creating an instance of this object that populate our dynamic fields with C# base types (`int`, `long`, `boolean` etc.)
```c#
public Models.Fingerprint ToFingerprint => new Models.Fingerprint
{
Hash = Fingerprint,
Data = new
{
Data.UserId,
Data.Name,
Data.Type,
Data.Domain,
Data.SiteName,
Data.Role,
Camps = new
,
Club = new
,
Package = new
},
Metadata = new
};
```
When using Newtonsoft we get the following result
```json
{
"id": null,
"createdAt": "2023-02-17T18:06:40.3767748+01:00",
"hash": "E929580C21FD36E878CCA03E38D95C57CD1DB7507A55965DFD036C2F9BFFE2AF821C616485EDAA7CF68A48E66A153F9A688829E692F440C78B56F7377AC37F5E",
"data": {
"userId": 1024439,
"name": "Eds FF",
"type": 3,
"domain": "laget.se",
"siteName": "EdsFF",
"role": 1,
"camps":
,
"club":
,
"package": {
"type": 0,
"package":
}
},
"metadata":
}
```
Why can't we longer use `dynamic` as a propety type?
Kind Regards
Erik
- related to
-
CSHARP-4534 Consider adding anonymous types to DefaultAllowedTypes
- Closed