System.Text.Json.Nodes.JsonNode no longer supports C# "dynamic" keyword in Preview 7 #25105
Closed
2 of 3 tasks
Labels
binary incompatible
Existing binaries may encounter a breaking change in behavior.
breaking-change
Indicates a .NET Core breaking change
🏁 Release: .NET 6
Issues and PRs for the .NET 6 release
doc-idea
Indicates issues that are suggestions for new topics [org][type][category]
Pri1
High priority, do before Pri2 and Pri3
System.Text.Json.Nodes.JsonNode no longer supports C# "dynamic" keyword.
Version introduced
.NET 6 Preview 7 (breaks functionality introduced in .NET 6 Preview 4)
Old behavior
The "dynamic" keyword could be used to get and set properties on the new
JsonObject
class such as:New behavior
The property name must be specified as a string, and "dynamic" not used:
Category
Reason for change
As discussed in dotnet/runtime#53195, the "dynamic" feature in C# is considered somewhat stale and adding a dependency to a new API (
JsonNode
and derived classes) is not considered a good practice.If a newer, more modern version of "dynamic" is introduced, this decision will be re-opened.
Recommended action
Use the string-based property name.
If "dynamic" is necessary, the previous workaround mentioned at dotnet/runtime#42097 is still valid. This will be verified and updated as necessary for .NET 6.0.
Feature area
Affected APIs
All
System.Text.Json.Nodes.JsonNode.Parse()
APIs are affected if the return value is assigned to a C# variable of typedynamic
variable.In addition, if
JsonSerializerOptions.UnknownTypeHandling
==UnknownTypeHandling.JsonNode
then allSystem.Text.Json.JsonSerializer.Deserialize*
APIs are affected if they usedynamic
orobject
for the type parameter and the return value is assigned to a C# variable of typedynamic
.Issue metadata
The text was updated successfully, but these errors were encountered: