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
Calling GetPath on a JsonObject child node in parallel triggers InvalidOperationException.
Reproduction Steps
vartree=(JsonNode.Parse(""" { "oh": "noes" } """)asJsonObject)!;// Workaround, do this once before parallel// tree.First().Value!.GetPath();Parallel.ForEach(Enumerable.Range(0,10), _ =>{tree.First().Value!.GetPath();});
Expected behavior
I expect parallel reads from the JsonNode/Object/Values to be thread safe.
Actual behavior
On JsonObject.GetPath, line string propertyName = FindValue(child)!.Value.Key; I get the following exception + stack trace:
System.InvalidOperationException: Nullable object must have a value.
at System.Nullable`1.get_Value()
at System.Text.Json.Nodes.JsonObject.GetPath(ValueStringBuilder& path, JsonNode child)
at System.Text.Json.Nodes.JsonNode.GetPath()
...
Just based on code inspection, I suspect the issue is that InitializeDictionary when called concurrently could end up returning two different dictionary instances with different node objects. While idempotent in terms of contents, reference equality will be different, and FindValue is relying on reference equality to locate the child object.
Activity
dotnet-policy-service commentedon Oct 11, 2025
Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis
See info in area-owners.md if you want to be subscribed.
MihuBot commentedon Oct 11, 2025
I'm a bot. Here is a possible related and/or duplicate issue (I may be wrong):
eangelin commentedon Oct 11, 2025
It does indeed look related, so perhaps this counts as a regression.
stephentoub commentedon Oct 11, 2025
Just based on code inspection, I suspect the issue is that InitializeDictionary when called concurrently could end up returning two different dictionary instances with different node objects. While idempotent in terms of contents, reference equality will be different, and FindValue is relying on reference equality to locate the child object.