Closed terryaney closed 3 months ago
Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis See info in area-owners.md if you want to be subscribed.
Duplicate of #77421. It was fixed in .NET 8 and the System.Text.Json 8.0.0 NuGet package. I would recommend updating to that as 7.0.x is out of support and has known vulnerabilities (unrelated to this particular issue).
Duplicate of #77421. It was fixed in .NET 8 and the System.Text.Json 8.0.0 NuGet package. I would recommend updating to that as 7.0.x is out of support and has known vulnerabilities (unrelated to this particular issue).
@eiriktsarpalis Curious, are you sure that is correct issue that was linked? That seems to focus more on thread safety, but maybe my issue was also resolved in that code.
Curious, are you sure that is correct issue that was linked?
Does the issue repro for you using STJ v8?
That seems to focus more on thread safety, but maybe my issue was also resolved in that code.
You mention that the issue happens randomly, which has the hallmarks of a race condition occurring. Your stacktrace stems from InitializeIfRequired
which was precisely the source of the race condition that got fixed.
Ah, ok then. And no, I haven't upgrade to .net8 yet. I tried when it came out and had some issues with web apis and I think something with Json as well. I took notes, but I'll give it another go in the near future. Thanks.
Description
I have a
JsonNode
object with following content:At random times, when I try to read the
key
property, anInvalidOperationException
is throw, but if I immediately retry reading it, it works.Reproduction Steps
With following 'locals':
source
=JsonNode
abovecell.Name
="key"
var historyIdCols = new[] { "id", "hisIndex" };
As mentioned, in the
try {}
that randomly fails with:Here is complete exception stack:
I'm trying to figure out if there is anything I can change in my code to eliminate this exception pattern.
Expected behavior
I wouldn't expect the first attempt to throw an exception when the same exact re-try attempt works.
Actual behavior
First attempt throws an exception when the same exact re-try attempt does not.
Regression?
No response
Known Workarounds
Retry the property get statement again.
Configuration
.NET7, x64, Windows 11 Pro.
Other information
No response