Repository navigation
Add per-call SerializationContext overloads - #1085
Merged
Merged
Conversation
…hods Adds overloads to the 8 core Serialize/Deserialize(Object)(Async) methods over MessagePackWriter/Reader and PipeWriter/Reader that take a SerializationContext in place of the CancellationToken. The cancellation token comes from the context. Existing overloads delegate to shared private cores passing StartingContext. Sync cores initialize the context in place by ref to avoid an extra copy of the large struct. New overloads carry [OverloadResolutionPriority(-1)] so an explicit 'default' argument still binds to the CancellationToken overloads. A context already initialized for an in-flight operation (e.g. one handed to a converter) is rejected with ArgumentException. Adds a protected CreateSerializationContext(ITypeShapeProvider, SerializationContext) overload; library code no longer calls the overload that implicitly uses StartingContext. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The implementation and tests are coherent; remaining feedback concerns minor documentation and message accuracy.
Review effort: Balanced
Findings: 3
Open (3)
What changed in this PR
Adds per-call SerializationContext support across core serialization APIs.
Changes:
- Adds sync/async typed and untyped context overloads.
- Rejects previously initialized contexts and consolidates shared implementation.
- Adds documentation, samples, and comprehensive tests.
| File | Description |
|---|---|
MessagePackSerializer.cs |
Adds context overloads and shared cores. |
SerializationContext.cs |
Adds initialized-context validation. |
PerCallSerializationContextTests.cs |
Tests context state, cancellation, depth, and overload resolution. |
CustomConverters.cs |
Demonstrates per-call state. |
custom-converters.md |
Documents the new API. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Avoid reflection-based type shape resolution in the new tests so they work under NativeAOT, including the Linux CI test executable. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1085 +/- ##
==========================================
+ Coverage 82.01% 82.27% +0.25%
==========================================
Files 256 257 +1
Lines 20866 21057 +191
Branches 2794 2795 +1
==========================================
+ Hits 17113 17324 +211
+ Misses 2864 2845 -19
+ Partials 889 888 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This was referenced Oct 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Why
Advanced callers need per-operation converter state and settings without creating a separate serializer for every call. Adding a context parameter to every overload would unnecessarily multiply the public API surface.
What changed
MessagePackWriter/MessagePackReaderandPipeWriter/PipeReader). Existing overloads preserve their signatures and delegate usingStartingContext; the context-taking overloads use the supplied context and its cancellation token.defaultcontinues to bind to the existing cancellation-token overloads.SerializationContext.GetConverterfor nested values. Add a protectedCreateSerializationContextoverload accepting a per-call context and move internal callers away from the overload that implicitly usesStartingContext.Validation
Success.Newtonsoft.Json.Linq.JToken.WriteToMissingMethodException; the same 19 failures reproduce with the changes stashed.