I am using the Newtonsoft JSON library to perform dynamic deserialisation on incoming raw JSON and have found something that I just can\'t explain.
The starting poin
I have/had a similar problem as I had a project that was doing a LOT of dynamic stuff.
What I narrowed it down to was..... JsonElement and serialization. Using Dynamic, the underlying type exists, and serialization to JSON what should it serialize that object to? Dynamic could be: a string, numeric,datetime, True, false etc. so they need to put a little meta data down too, so that when you refer to the dynamic, it knows that on serialization
So... when you serialize, the I believe the dynamic gets converted to a JsonElement - specifying a ValueKind, and a Value as properties.
When you de-serialize, things get complicated... JSON to C# will match the property in the class, and if its dynamic as a destination - something needs to restore the dynamic based on the JSON Element information.
This is where things get fuzzy, but I know for sure that if you look into the Serialzation, and you see ValueKind, you are likely to have a problem on the other side.
Also watch the Text.Json (MS) deserialization, and serialization, as I believe their is a difference in how newtonsoft and MS handle the serialization and deserialization of dynamics.