-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
System.Text.Json doesn't deserialize IDictionary with TKey types other than string #44726
Comments
FYI to JSON team: deserializing to a |
This was fixed for 6.0 in #42835. See that PR for more info. The workaround for 5.0 is to use another dictionary type such as @GrabYourPitchforks support for non-string dictionary keys was added in 5.0 (PR, design doc). This support is scoped to primitives such as I've created a doc issue to provide security guidance about this feature: dotnet/docs#21724. |
Reopening for servicing consideration in 5.0. |
Fixed for 5.0.2 in #45449. |
Description
System.Text.Json.Deserialize()
cannot deserialize to IDictionary where TKey has type other than string.I have following example:
This code above would throw exception
System.InvalidCastException : Unable to cast object of type 'System.Collections.Generic.Dictionary2[System.String,System.String]' to type 'System.Collections.Generic.IDictionary2[System.Int32,System.String]'.
However if i only change IDictinary type to Dictionary it will work. It seems strange for me because similar example for
ICollection<int>
would work and i'll getList
object.Configuration
.net 5.0.100
Windows 10 18363.1198 (x64)
The text was updated successfully, but these errors were encountered: