Skip to content

fix(http-client-csharp): include protocol-only paging response model in code model#10422

Open
JoshLove-msft wants to merge 3 commits intomicrosoft:mainfrom
JoshLove-msft:fix/pageable-no-convenience
Open

fix(http-client-csharp): include protocol-only paging response model in code model#10422
JoshLove-msft wants to merge 3 commits intomicrosoft:mainfrom
JoshLove-msft:fix/pageable-no-convenience

Conversation

@JoshLove-msft
Copy link
Copy Markdown
Contributor

Fixes #9391

When a paging operation is annotated with @convenientAPI(false), TCGC does not include the anonymous response model (the model containing the @nextLink/@continuationToken property) in sdkPackage.models. The C# emitter previously snapshotted __typeCache.types BEFORE processing clients, so models reachable only via operations were excluded from the code model. The generator's CollectionResultDefinition then emitted code that cast the raw response to a non-existent model class (e.g., ((MyOpResponse)result).Next), producing a CS0234 build error.

Fix

In client-model-builder.ts, take the models/enums snapshot from __typeCache.types AFTER fromSdkClients runs, so any types that were only visited during operation/response processing are captured. (constants was already snapshotted after fromSdkClients — this aligns models/enums with that pattern.)

Test

Added a unit test in operation-paging.test.ts that asserts the anonymous response model for a @convenientAPI(false) paging op is present in the code model.

Manually reproduced by adding such an op to Sample-TypeSpec — without the fix, dotnet build fails with CS0234; with the fix it succeeds.

…in code model

When a paging operation is annotated with @convenientAPI(false), TCGC does
not include the anonymous response model (the model containing the
@nextlink or @continuationToken property) in sdkPackage.models. The C#
emitter previously snapshotted __typeCache.types BEFORE processing
clients, so any models reachable only via operations were excluded from
the code model. The generator's CollectionResultDefinition then emitted
code that referenced a non-existent model class.

Take the snapshot AFTER fromSdkClients runs so types added during
operation/response processing are captured.

Fixes microsoft#9391

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 Apr 18, 2026
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 18, 2026

Open in StackBlitz

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

commit: be8af43

@github-actions
Copy link
Copy Markdown
Contributor

No changes needing a change description found.

@azure-sdk
Copy link
Copy Markdown
Collaborator

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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] Pageable operation's generated code cannot compile if convenience method is turned off

2 participants