Repository navigation
Refuse to write Newtonsoft JSON deeper than it can read back [patch] - #158
Conversation
Newtonsoft enforces MaxDepth only when reading, so TrySerialize wrote graphs deeper than 64 levels that Deserialize then returned null for. Write through a JsonTextWriter that throws past the same explicit MaxDepth, which TrySerialize reports as false. Fixes #155 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SETCEsuMvZFcF6qXRguNds
|
This failure isn't caused by this PR, which only changes the Newtonsoft serialization provider. The cause is a timing race in persistence code that already exists on Proposed fix, separate from this PR: in I've re-run the failed job once. Generated by Claude Code |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SETCEsuMvZFcF6qXRguNds
|



Fixes #155
What changed
Newtonsoft.Json enforces
MaxDepth(default 64) only when reading, soNewtonsoftJsonSerializationProvider.TrySerializewrote graphs of any depth and returnedtrue, whileDeserializeon the same output returnednull.MaxDepth = 64, so the reader's limit is stated rather than inherited.TrySerializewrites through a privateDepthLimitedJsonTextWriterthat throwsJsonWriterExceptiononce an object or array nests past that same limit. The existing catch turns it intofalse.Any graph
TrySerializeaccepts now deserializes back.Tests
TrySerialize_DeepChain_SucceedsOnlyWhenItDeserializeswith depths 64, 65 and 200: 64 round-trips; 65 and 200 makeTrySerializereturnfalse. Onmain, the 65 and 200 cases fail (serialize returnstrue).Essentials.Testssuite on net10.0: 1088 passed. The provider project builds clean on every target.Note
This and #157 (#154, buffer output until success) touch the same
using JsonTextWriterline, so whichever merges second needs a small merge. With both in, a depth failure also leaves the caller's writer empty, as the issue asks.Generated by Claude Code