You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adding a JsonElement via JsonArray.Add throws an exception with .NET 8. In .NET 7 it worked without throwing.
It is interesting that JsonArray.Add worked in .NET 7 but JsonValue.Create fails in both .NET 7/8 when passing in a JsonElement with ValueKind.Object/Array.
Throws a System.InvalidOperationException: "The element cannot be an object or array."
bei System.Text.Json.ThrowHelper.ThrowInvalidOperationException_NodeElementCannotBeObjectOrArray()
bei System.Text.Json.Nodes.JsonValue.VerifyJsonElementIsNotArrayOrObject(JsonElement& element)
bei System.Text.Json.Nodes.JsonValue.Create[T](T value, Nullable`1 options)
bei System.Text.Json.Nodes.JsonArray.Add[T](T value)
Regression?
Yes, it works with .NET 7.0
Known Workarounds
For this particular case the JsonDocument could be added instead of the RootElement.
A general workaround would be #70427 (comment)