Skip to content

[http-client-csharp] Emit async modifier when customizing an async method via a partial method (CS4032)#11222

Merged
jorgerangel-msft merged 3 commits into
mainfrom
copilot/fix-async-modifier-omission
Jul 10, 2026
Merged

[http-client-csharp] Emit async modifier when customizing an async method via a partial method (CS4032)#11222
jorgerangel-msft merged 3 commits into
mainfrom
copilot/fix-async-modifier-omission

Conversation

Copilot AI commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Customizing an async client method via a C# partial method declaration produced an implementing declaration without the async modifier, while the generated body uses await — resulting in compiler error CS4032.

A partial declaration cannot carry async (that modifier belongs to the implementing declaration), so building the implementation signature from the customer's declaration modifiers dropped it. The generated (non-custom) path adds Async separately, so only the custom-code path was affected.

Changes

  • PartialMethodCustomization.BuildPartialSignature: added an optional additionalModifiers parameter, OR-ed into the resulting signature modifiers. Backward-compatible and reusable by downstream emitters.
  • ScmMethodProviderCollection: both custom-code call sites (BuildProtocolMethod, BuildConvenienceMethod) now pass MethodSignatureModifiers.Async when isAsync && _pagingServiceMethod == null, mirroring the condition already used by the generated path.
  • Tests: added CanCustomizeAsyncMethodSignature and its custom-code test data asserting the Async modifier is present on the customized async protocol method.

Result

Given a custom partial declaration:

public partial Task<ClientResult> GetWidgetAsync(string id, RequestOptions options);

the generated implementation now emits:

private async partial Task<ClientResult> GetWidgetAsync(string id, RequestOptions options)
{
    using PipelineMessage message = CreateGetWidgetRequest(id, options);
    return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false));
}

Note: @typespec/http-client-csharp is not registered in Chronus, so no changelog entry was added.

Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@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 Jul 9, 2026
Copilot AI changed the title [WIP] Fix async modifier omission in partial method customization [http-client-csharp] Emit async modifier when customizing an async method via a partial method (CS4032) Jul 9, 2026
Copilot AI requested a review from jorgerangel-msft July 9, 2026 19:29
@pkg-pr-new

pkg-pr-new Bot commented Jul 9, 2026

Copy link
Copy Markdown

Open in StackBlitz

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

commit: 758281d

Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
@jorgerangel-msft
jorgerangel-msft added this pull request to the merge queue Jul 10, 2026
Merged via the queue into main with commit eec876e Jul 10, 2026
29 checks passed
@jorgerangel-msft
jorgerangel-msft deleted the copilot/fix-async-modifier-omission branch July 10, 2026 16:29
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.

[http-client-csharp] Customizing an async method via a partial method omits the async modifier (CS4032)

4 participants