Skip to content

fix(http-client-csharp): correct return type namespace and parameter names in partial method customization#11057

Closed
JoshLove-msft wants to merge 2 commits into
microsoft:mainfrom
JoshLove-msft:joshlove/fix-partial-method-customization
Closed

fix(http-client-csharp): correct return type namespace and parameter names in partial method customization#11057
JoshLove-msft wants to merge 2 commits into
microsoft:mainfrom
JoshLove-msft:joshlove/fix-partial-method-customization

Conversation

@JoshLove-msft

Copy link
Copy Markdown
Contributor

Fixes two bugs in the C# emitter's partial method customization feature, observed in Azure/azure-sdk-for-net#59749:

  1. Missing namespace on return types — generated partial implementations rendered return types as global::.DeallocateResourceOperationResult (empty namespace). The implementation signature was built from the customer's parsed partial declaration, whose return type references not-yet-generated models. Roslyn surfaces those as error types with an empty namespace, which CodeWriter.AppendType writes as global::.TypeName.
  2. 0 appended to parameter names — e.g. resourceGroupResource0. This happens when the method signature and body reference different ParameterProvider instances that share the same name, triggering the writer's disambiguation.

Fix

  • BuildPartialSignature now accepts an optional CSharpType? returnType and uses returnType ?? customSignature.ReturnType, so callers can supply the generator's resolved return type instead of the customer's parsed (unresolved) one.
  • ScmMethodProviderCollection (convenience + protocol paths) now pass the generator's resolved return type (GetResponseType(...)) and clone parameters from the generator's resolved parameters while taking the customer's names. The protocol body shares the same renamed parameter instances as the signature, preventing the 0 suffix.

Tests

  • Added PartialMethodCustomizationTests (3 tests) verifying the generator return type is used, the null fallback, and that cloned parameters keep generator types with custom names.
  • Existing ClientProviderCustomizationTests (18 tests) still pass.

Note: the management generator (in azure-sdk-for-net) is the actual consumer producing the buggy output; these shared helpers now enable correct usage, and this repo's data-plane paths are correct.

…names in partial method customization

Fixes two bugs in the partial method customization feature:
- Return types rendered with an empty namespace (global::.TypeName) because the
  partial implementation was built from the customer's parsed declaration, whose
  return type references not-yet-generated models (Roslyn error types with no
  namespace).
- A '0' was appended to parameter names when the signature and body referenced
  different ParameterProvider instances with the same name.

BuildPartialSignature now accepts the generator's resolved return type, and the
ScmMethodProviderCollection call sites pass the generator return type and clone
from the generator's parameters (resolved types), sharing instances between
signature and body.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@microsoft-github-policy-service microsoft-github-policy-service Bot added the emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp label Jun 23, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@pkg-pr-new

pkg-pr-new Bot commented Jun 23, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/http-client-csharp@11057

commit: c204eee

@github-actions

Copy link
Copy Markdown
Contributor

No changes needing a change description found.

@azure-sdk-automation

Copy link
Copy Markdown

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant