feat(serialization): add codecs for FrozenDictionary and FrozenSet - #10270
Merged
Merged
Conversation
Add Orleans serialization codecs and copiers for the .NET 8 frozen collection types FrozenDictionary<TKey, TValue> and FrozenSet<T>, guarded by NET8_0_OR_GREATER so they only compile on supporting platforms. The copiers deep-copy contents in the same manner as the immutable collection copiers, short-circuiting to a shallow copy when the element copiers are shallow-copyable. Because the frozen collection types are abstract base types whose runtime instances are internal subtypes (potentially of different generic arity), the copiers implement IDerivedTypeCopier and CodecProvider.CreateCopierInstance now advances the field type and search type in lockstep when resolving derived-type copiers, mirroring the existing codec-side logic. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 564fb626-a0b7-4860-97fd-3e00d83d60dc
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
There was a problem hiding this comment.
Pull request overview
Adds built-in Orleans.Serialization support for .NET 8 frozen collections so FrozenDictionary<TKey, TValue> and FrozenSet<T> can be serialized/copied in grain calls, storage payloads, and stream events on NET8+.
Changes:
- Add new codecs, surrogates, and deep copiers for
FrozenDictionary<TKey, TValue>andFrozenSet<T>(NET8+ only). - Update copier resolution in
CodecProviderto correctly handle derived types whose generic arity differs from their base type (needed for frozen collections’ internal runtime types). - Add unit tests covering round-trip serialization and copier behavior, including comparer preservation.
Show a summary per file
| File | Description |
|---|---|
| test/Orleans.Serialization.UnitTests/BuiltInCodecTests.cs | Adds codec and copier tests for frozen collections and validates comparer preservation. |
| src/Orleans.Serialization/Serializers/CodecProvider.cs | Fixes derived-type copier lookup to advance field/search types together when walking base types. |
| src/Orleans.Serialization/Codecs/FrozenSetCodec.cs | Introduces NET8+ codec/surrogate/copier for FrozenSet<T>. |
| src/Orleans.Serialization/Codecs/FrozenDictionaryCodec.cs | Introduces NET8+ codec/surrogate/copier for FrozenDictionary<TKey, TValue>. |
Copilot's findings
- Files reviewed: 4/4 changed files
- Comments generated: 2
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 564fb626-a0b7-4860-97fd-3e00d83d60dc
This was referenced Jul 22, 2026
This was referenced Jul 29, 2026
This was referenced Jul 29, 2026
Merged
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Problem
Orleans had no serialization support for the frozen collection types introduced in .NET 8 (
FrozenDictionary<TKey, TValue>andFrozenSet<T>). Attempting to serialize a grain call, storage payload, or stream event containing one of these types would fail.Solution
Add serialization codecs and copiers for
FrozenDictionary<TKey, TValue>andFrozenSet<T>, modeled on the existing immutable-collection codecs. They are guarded by#if NET8_0_OR_GREATERso they only compile on platforms that ship the frozen collections (the netstandard2.1 target excludes them).Notable details:
List<>plus the collection's comparer (stored only when non-default). Reading entries straight out of the source collection avoids re-hashing keys when constructing the surrogate.IDerivedTypeCopier, andCodecProvider.CreateCopierInstancenow advances the field type and search type in lockstep when resolving derived-type copiers, mirroring the existing codec-side logic. Without this, resolving a copier for a subtype with mismatched arity threw anArgumentExceptionfromMakeGenericType.Tests cover round-tripping through the codec, copier behavior (including mutable element types), and comparer preservation.
Microsoft Reviewers: Open in CodeFlow