[CSHARP-4532] We're no longer able to use dynamic as property types Created: 17/Feb/23 Updated: 02/Mar/23 Resolved: 02/Mar/23 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | Serialization |
| Affects Version/s: | 2.19.0 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Unknown |
| Reporter: | Erik Hennerfors | Assignee: | Boris Dogadov |
| Resolution: | Duplicate | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Documentation Changes Summary: | 1. What would you like to communicate to the user about this feature? |
||||||||
| Description |
|
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 [BsonElement("createdAt"), BsonDateTimeOptions(Kind = DateTimeKind.Utc)] public DateTime CreatedAt { get; set; } = DateTime.Now; [BsonElement("data")] public object Data { get; set; } [BsonElement("metadata")] } We're then creating an instance of this object that populate our dynamic fields with C# base types (`int`, `long`, `boolean` etc.) ```c# , , }, }; When using Newtonsoft we get the following result ```json , , } } Why can't we longer use `dynamic` as a propety type? Kind Regards |
| Comments |
| Comment by Boris Dogadov [ 02/Mar/23 ] | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Thanks for reporting this erik.hennerfors@laget.se. Follow up work will be done in Closing this ticket. | |||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Erik Hennerfors [ 24/Feb/23 ] | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi
We'll dig into our dependencies to see if one of those is adding custom serializers! | |||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Boris Dogadov [ 23/Feb/23 ] | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Driver uses static serialization registry, and this exception indicates that ObjectSerializer is already registered. You need to ensure that
is executed in some initialization code before any other serialization setup/operations are executed. Please note that there is also
method, but if will throw exception is there is already other serializer registered with different settings (for example different lambda instance). | |||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Erik Hennerfors [ 23/Feb/23 ] | |||||||||||||||||||||||||||||||||||||||||||||||||
|
@Boris Dogadov We've tried adding the following
But we're getting the following errors,
| |||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Erik Hennerfors [ 23/Feb/23 ] | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi Boris Dogadov Best regards | |||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Boris Dogadov [ 18/Feb/23 ] | |||||||||||||||||||||||||||||||||||||||||||||||||
|
2.19 introduced a security fix (
Please note that this is a quick and informal way to validate whether the type is anonymous . There are other ways to check whether a type is an anonymous one. We'll be researching this further in | |||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Erik Hennerfors [ 17/Feb/23 ] | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Did not realise that I can't edit the issue after creating it, but we're getting the following exception
Here is the json representation of the object we're trying to save fo mongo that is converted to json using Newtonsoft.
|