Repository navigation
[csharp][generichost] Use a single context - #25593
Merged
wing328 merged 2 commits intoNov 9, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 331 files
Note: This PR contains a large number of files. cubic selects up to 200 of the highest-priority eligible files for this review, so some files may not have been reviewed.
View guided diff | Re-trigger cubic
Member
|
FYI. Just filed #25597 to fixed duplicated methods in csharp client codegen. |
3 tasks done
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.
Please merge these first:
#25486
#25548
Fixes #20895
Fixes #25158
Problem
The C# Generic Host generator created one
JsonSerializerContextper model. This duplicated source-generated metadata across the client (#20895) and only masked collisions by spreading contracts across multiple contexts.Nested enums expose the underlying correctness problem. Types such as
ImageAsset.TypeEnumandDocumentAsset.TypeEnumare distinct CLR types, butSystem.Text.Jsongives both metadata properties the nameTypeEnum. This producesSYSLIB1031, omits one contract, and can result in incomplete fast-path serialization (#25158). Nullable enums and theirOptionor collection wrappers can collide in the same way.Solution
This change generates one
OpenApiSerializationContextfor the client and registers it before the existing reflection fallback. Collision-prone enum, nullable, optional, and container contracts receive deterministic, globally uniqueTypeInfoPropertyNamevalues, while every generated model remains a serialization root.Removing the model-local contexts eliminates duplicated metadata and gives the generated client one consistent serialization boundary. The context, resolver registration, and model namespace import are all gated when a specification has no models, so no-model clients remain valid.
Generated tests now resolve every explicit contract through the shared context, and the source-generation samples and documentation reflect the new API.
PR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
Summary by cubic
Consolidates the per-model source-generated JSON serialization contexts in the C#
generichostlibrary into a single sharedOpenApiSerializationContext.XxxSerializationContextclasses generated inside each model file with one context in theClientnamespace that registers all model types and inner enum types.TypeInfoPropertyNamevalues for inner enums to avoid name collisions.HostConfigurationto combine the new single context withDefaultJsonTypeInfoResolverand adds DI tests verifying the shared context contains every generated model contract.Migration
ActivitySerializationContextmust useOpenApiSerializationContextinstead.Written for commit 98eddc8. Summary will update on new commits.