Closed orange-puff closed 2 years ago
I made a PR with 2 unit tests related to the issue https://github.com/RicoSuter/Namotion.Reflection/pull/69/
Dictionary validation is likely indirectly related to #67 (aka Namotion.Reflection is unable to detect nullability in the dictionary).
However, the case you're describing is weird, I don't see where the "cast" occurs. Do you have a stack trace?
Does the deserialization succeed, even when you gave a "User" instead of a "user".
Yes, serialization works. But just to be consist I changed "User" to "user" to match the JsonProperty
attribute.
Here is the stack trace:
Unhandled exception. System.InvalidCastException: Unable to cast object of type 'System.String' to type 'MyClass'.
at Namotion.Reflection.ObjectExtensions.ValidateNullability(Object obj, ContextualType type, HashSet`1 checkedObjects, List`1 errors, Boolean stopFirstFail)
at Namotion.Reflection.ObjectExtensions.ValidateNullability(Object obj, ContextualType type, HashSet`1 checkedObjects, List`1 errors, Boolean stopFirstFail)
at Namotion.Reflection.ObjectExtensions.EnsureValidNullability(Object obj, Boolean checkChildren)
at test.Program.Main(String[] args) in C:\Users\john.mancini\Desktop\test\test\Program.cs:line 33
Is this now resolved?
I am not sure. I can reopen if you'd like
For example
This code throws an error
'Unable to cast object of type 'System.String' to type 'test.MyClass'.'
I am not sure if it is known that there are issues related to ensuring the validations of dictionaries. If so, we can delete this issue. A similar error is thrown for Dictionary<int, T>. But T seems to have to be a custom class, or at least notint
orstring