Skip to content

Conversation

@layomia
Copy link
Contributor

@layomia layomia commented Sep 29, 2020

Prevents InvalidCastException when deserializing the following dictionary types (exhaustive list) and the key type is not typeof(string):

  • typeof(IDictionary<,>)
  • typeof(ImmutableDictionary<,>)
  • typeof(IImmutableDictionary<,>)
  • typeof(IReadOnlyDictionary<,>)

The workaround for .NET 5 is to use a custom converter for these types, or use a different dictionary type.

Deserializing other dictionary types e.g. class MyCustomDictionary : IDictionary<int, int>, Dictionary<DateTime, string>, class MyCustomReadOnlyDictionary : IReadOnlyDictionary<Guid, int> etc works fine.

@layomia layomia added this to the 6.0.0 milestone Sep 29, 2020
@layomia layomia self-assigned this Sep 29, 2020
Copy link
Member

@jozkee jozkee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

@layomia layomia merged commit f63b0c1 into dotnet:master Sep 30, 2020
@layomia layomia deleted the dictionary branch September 30, 2020 03:43
@danmoseley
Copy link
Member

Did this work in 3.1?

@jozkee
Copy link
Member

jozkee commented Sep 30, 2020

@danmosemsft support for non-string dictionary keys was added in 5.0 (this was not a regression from 3.1), if someone wants the feature to work on 3.1 and they specifically need one of the types fixed in this PR, they would have to use a daily build of .NET 6 or wait for .NET 6 preview 1.

@danmoseley
Copy link
Member

@jozkee sounds good

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants