-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Description
Description
The following snippet succeeds when compiled and run against net8.0, but throws an exception when compiled and run against net9.0
using System.Text.Json;
using System.Text.Json.Nodes;
string json = """
{ "names": ["Chuck"] }
""";
var dict = JsonSerializer.Deserialize<Dictionary<string, JsonValue>>(json);
Reproduction Steps
- create a new net8.0 console app and add the following code:
using System.Text.Json;
using System.Text.Json.Nodes;
string json = """
{ "names": ["Chuck"] }
""";
var dict = JsonSerializer.Deserialize<Dictionary<string, JsonValue>>(json);
- run the app
- change net8.0 to net9.0
- run the app
Expected behavior
The serializaiton succeeds
Actual behavior
in net9.0, the deserialization throws an exception:
System.InvalidOperationException: 'The element cannot be an object or array.'
Regression?
Yes, this works in net8 but not in net9
Known Workarounds
Deserializing to Dictionary<string, JsonNode>
appears to work.
Configuration
dotnet --list-sdks
8.0.406 [C:\Program Files\dotnet\sdk]
9.0.200 [C:\Program Files\dotnet\sdk]
9.0.300-preview.0.25127.19 [C:\Program Files\dotnet\sdk]
dotnet --list-runtimes
Microsoft.AspNetCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 9.0.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 9.0.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.13 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 9.0.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Other information
No response