System.Text.Json: Calling Write method of default dictionary converter from a custom dictionary converter fails with NRE #106697
Labels
area-System.Text.Json
needs-further-triage
Issue has been initially triaged, but needs deeper consideration or reconsideration
Milestone
Description
STJ version: 9.0.0-preview.7.24405.7
Given is an example custom
Dictionary<string, int>
dictionary converter (stripped down to the bits essential to the issue at hand) which invokes the default dictionary converter (obtained fromJsonSerializerOptions.Default
) in its Write method.Serializing a
Dictionary<string, int>
dictionary using this converter fails with a NRE in the default converter's internalOnTryWrite
method because it looks likestate.Current.JsonTypeInfo.ElementTypeInfo
is null when trying to getjsonTypeInfo.ElementTypeInfo!.PropertyInfoForTypeInfo
:runtime/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/JsonDictionaryConverter.cs
Line 361 in 9876ed1
Reproduction Steps
Expected behavior
The dictionary should be deserialized normally without exceptions.
Actual behavior
Regression?
Not sure, but i don't think so.
I tested also with 8.0.4, 8.0.0, as well as 7.0.4, and these three also throw an NRE.
Known Workarounds
So far I got no idea for a workaround except (re)implementing the dictionary serialization logic in the custom converter. Which can become quite burdensome if the custom converter is using a generic type parameter for the dictionary value type (with the help of a converter factory).
Configuration
.NET version: 8.0
STJ version: 9.0.0-preview.7.24405.7
OS: Windows 11 x64
Other information
No response
The text was updated successfully, but these errors were encountered: