Skip to content

Fix http-server-csharp crash on interfaces with template operations#9894

Open
Copilot wants to merge 6 commits intomainfrom
copilot/fix-typespec-http-server-emit
Open

Fix http-server-csharp crash on interfaces with template operations#9894
Copilot wants to merge 6 commits intomainfrom
copilot/fix-typespec-http-server-emit

Conversation

Copy link
Contributor

Copilot AI commented Mar 4, 2026

  • Understand root cause: interfaceDeclarationOperations in service.ts doesn't filter template operations, causing TemplateParameter types to be passed to emitType
  • Add isTemplateDeclaration(operation) guard in interfaceDeclarationOperations loop
  • Add TemplateParameter guard in #resolveOperationResponse as a safety net (with comment)
  • Add regression test: verifies template operations are skipped and non-template operations work
  • Add changeset entry (updated description per review feedback)
  • Merged latest changes from main
Original prompt

This section details on the original issue you should resolve

<issue_title>[Bug]: Unable to emit @typespec/http-server-csharp using azure-rest-api-specs typespec</issue_title>
<issue_description>### Describe the bug

Considering the PR and branch containerregistry-conversion, I run into issues when trying to compile typespec with emit option "@typespec/http-server-csharp".

Log:

> tsp compile specs/containerregistry/main.tsp

TypeSpec compiler v1.4.0

✔ Compiling
✔ @azure-tools/typespec-autorest 819ms specs/containerregistry/
× Running @typespec/http-server-csharp...
Emitter "@typespec/http-server-csharp" crashed! This is a bug.
Please file an issue at https://github.com/microsoft/typespec/issues

Error: Encountered type TemplateParameter which we don't know how to emit.
    at compilerAssert (file:///C:/work/acr/dev/src/ACR.RP/ACR.RP.Web.Spec/node_modules/@typespec/compiler/dist/src/core/diagnostics.js:150:11)
    at typeEmitterKey (file:///C:/work/acr/dev/src/ACR.RP/ACR.RP.Web.Spec/node_modules/@typespec/asset-emitter/dist/src/asset-emitter.js:618:17)
    at Object.emitType (file:///C:/work/acr/dev/src/ACR.RP/ACR.RP.Web.Spec/node_modules/@typespec/asset-emitter/dist/src/asset-emitter.js:238:25)
    at #resolveOperationResponse (file:///C:/work/acr/dev/src/ACR.RP/ACR.RP.Web.Spec/node_modules/@typespec/http-server-csharp/dist/src/lib/service.js:744:26)
    at CSharpCodeEmitter.interfaceDeclarationOperations (file:///C:/work/acr/dev/src/ACR.RP/ACR.RP.Web.Spec/node_modules/@typespec/http-server-csharp/dist/src/lib/service.js:586:77)
    at file:///C:/work/acr/dev/src/ACR.RP/ACR.RP.Web.Spec/node_modules/@typespec/asset-emitter/dist/src/asset-emitter.js:376:55
    at withTypeContext (file:///C:/work/acr/dev/src/ACR.RP/ACR.RP.Web.Spec/node_modules/@typespec/asset-emitter/dist/src/asset-emitter.js:519:9)
    at invokeTypeEmitter (file:///C:/work/acr/dev/src/ACR.RP/ACR.RP.Web.Spec/node_modules/@typespec/asset-emitter/dist/src/asset-emitter.js:366:9)
    at Object.emitInterfaceOperations (file:///C:/work/acr/dev/src/ACR.RP/ACR.RP.Web.Spec/node_modules/@typespec/asset-emitter/dist/src/asset-emitter.js:327:20)
    at CSharpCodeEmitter.interfaceDeclaration (file:///C:/work/acr/dev/src/ACR.RP/ACR.RP.Web.Spec/node_modules/@typespec/http-server-csharp/dist/src/lib/service.js:542:22)

--------------------------------------------------
Library Version                0.58.0-alpha.20
TypeSpec Compiler Version      1.4.0
--------------------------------------------------

My configuration looks as follows:

emit:
  - "@azure-tools/typespec-autorest"
  - "@typespec/http-server-csharp"
options:
  ...
  "@typespec/http-server-csharp":
    emitter-output-dir: "{project-root}/typespec/codegen"
    output-type: "models"
    collection-type: "enumerable"

Surprised, considering that emitter "@azure-tools/typespec-autorest" works as expected, and also used the "@typespec/openapi3" to further verify, and it works as expected. But for some reason, the csharp generator runs into an issue.

Reproduction

The description is pretty straightforward.
I will go ahead and create a fork so you may clone and reproduce locally, and update the thread.

Checklist

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

- Skip template operations in interfaceDeclarationOperations
- Add safety guard in #resolveOperationResponse for TemplateParameter
- Add regression test for interfaces with template operations
- Add changeset entry

Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix bug with emitting @typespec/http-server-csharp Fix http-server-csharp crash on interfaces with template operations Mar 4, 2026
Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
@markcowl
Copy link
Contributor

markcowl commented Mar 4, 2026

@copilot please pull the latest changes from main

Copy link
Contributor Author

Copilot AI commented Mar 4, 2026

@copilot please pull the latest changes from main

Done — merged latest from main in 578f446.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 4, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/http-server-csharp@9894

commit: add0d2e

@github-actions
Copy link
Contributor

github-actions bot commented Mar 4, 2026

All changed packages have been documented.

  • @typespec/http-server-csharp
Show changes

@typespec/http-server-csharp - fix ✏️

Fix crash when emitting interfaces that contain template operations. Template operations (e.g. getItem<T>(): T) within interfaces will simply be skipped when emitting the interface.

@markcowl markcowl marked this pull request as ready for review March 4, 2026 21:38
@azure-sdk
Copy link
Collaborator

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Unable to emit @typespec/http-server-csharp using azure-rest-api-specs typespec

3 participants