Fix partial method customization parameter renaming#11058
Merged
JoshLove-msft merged 4 commits intoJun 23, 2026
Conversation
CreatePartialMethodFromCustomSignature passed the custom signature's parameters as the generator parameters, so the generated partial implementation's signature referenced different parameter declarations than its body and XML docs. The writer's name de-duplication then appended a numeric suffix (e.g. input0) to the signature parameters, producing code that does not compile. Pass the generated method's parameters as the generator parameters so the signature, body, and XML docs share the same parameter declarations. Also document that types generated into the same assembly must be fully qualified with global:: in a partial method declaration. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a C# generator bug where customizing a generated method via a hand-written partial declaration could produce mismatched parameter declarations between the signature and body (leading to de-duplication suffixes like input0 and resulting compilation failures). This aligns TypeProvider.CreatePartialMethodFromCustomSignature with the intended RenameAndCloneParameters(generatorParameters, customParameters) contract and adds a regression test + documentation guidance for partial signatures.
Changes:
- Fix partial-method parameter cloning to use the generated method’s parameter providers as the metadata/declaration source.
- Add a regression test + custom-code fixture ensuring generated partial implementations keep body/signature parameter names aligned.
- Document a
global::qualification requirement when partial declarations reference types generated into the same assembly.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/TypeProviderTests.cs | Adds a regression test validating partial-method customization does not introduce parameter suffix renames. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/TestData/TypeProviderTests/CustomPartialMethodImplementationKeepsParameterNames/Custom.cs | Adds custom partial declaration fixture used by the new regression test. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Providers/TypeProvider.cs | Fixes parameter source passed into RenameAndCloneParameters to keep signature/body/XML doc declarations consistent. |
| packages/http-client-csharp/.tspd/docs/customization.md | Documents the need to fully qualify same-assembly generated types with global:: in partial declarations. |
| .chronus/changes/fix-partial-method-parameter-rename-2026-6-23-9-50-0.md | Adds a Chronus changelog entry for the change. |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
commit: |
|
You can try these changes here
|
Contributor
|
No changes needing a change description found. |
JoshLove-msft
approved these changes
Jun 23, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
When a partial method declaration's return type references a type generated into the same assembly, the type is unresolved when the declaration is read (Roslyn error type with no namespace), producing malformed 'global::.TypeName' output. BuildPartialSignature now accepts the generator's resolved return type, and CreatePartialMethodFromCustomSignature passes it. C# requires a partial method's declaration and implementation to share the same return type, so the generator's resolved type is necessarily correct. Removes the docs note that asked users to qualify return types with global::. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
jsquire
approved these changes
Jun 23, 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.
Problem
When a hand-written
partialmethod declaration customizes a generated method (the documented "Customize a generated client method's signature" feature), the generated partial implementation comes out with parameter names that don't compile.TypeProvider.CreatePartialMethodFromCustomSignaturepassedcustomSignature.Parametersas both arguments toRenameAndCloneParameters. The intended contract is(generatorParameters, customParameters): the first carries the generator metadata and the parameter declarations referenced by the method body and XML docs; the second only supplies the names.Because the custom parameters were used for the signature, the signature ended up referencing different
ParameterProvider/CodeWriterDeclarationinstances than the body and XML docs. The writer's name de-duplication then appended a numeric suffix, e.g.:Fix
Pass
generatedMethod.Signature.Parametersas the generator parameters so the signature, body, and XML docs all share the same parameter declarations. This matches the contract documented onRenameAndCloneParametersand the existing correct usage inScmMethodProviderCollection.BuildConvenienceMethod.Tests
CustomPartialMethodImplementationKeepsParameterNames(fails before the fix showinginput0, passes after).Microsoft.TypeSpec.Generatortests + 1436Microsoft.TypeSpec.Generator.ClientModeltests.Docs
Added a note to
customization.md: types generated into the same assembly must be fully qualified withglobal::in a partial method declaration, since they are unresolved symbols when the declaration is read.