From e676cfa72c802a3a5e542ca151998b048092b307 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 4 Mar 2026 00:52:46 +0000 Subject: [PATCH 1/3] Initial plan From bad9f1d4df7e9eb1026bf89884a2423644690779 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 4 Mar 2026 01:11:40 +0000 Subject: [PATCH 2/3] fix: handle TemplateParameter types in http-server-csharp emitter - 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> --- ...rver-csharp-template-parameter-2026-03-04.md | 7 +++++++ packages/http-server-csharp/src/lib/service.ts | 8 +++++++- .../http-server-csharp/test/generation.test.ts | 17 +++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 .chronus/changes/fix-http-server-csharp-template-parameter-2026-03-04.md diff --git a/.chronus/changes/fix-http-server-csharp-template-parameter-2026-03-04.md b/.chronus/changes/fix-http-server-csharp-template-parameter-2026-03-04.md new file mode 100644 index 00000000000..e6973995735 --- /dev/null +++ b/.chronus/changes/fix-http-server-csharp-template-parameter-2026-03-04.md @@ -0,0 +1,7 @@ +--- +changeKind: fix +packages: + - "@typespec/http-server-csharp" +--- + +Fix crash when emitting interfaces that contain template operations. Template operations (e.g. `getItem(): T`) within interfaces no longer cause "Encountered type TemplateParameter which we don't know how to emit" error. diff --git a/packages/http-server-csharp/src/lib/service.ts b/packages/http-server-csharp/src/lib/service.ts index 6f9b671f398..79e6863db81 100644 --- a/packages/http-server-csharp/src/lib/service.ts +++ b/packages/http-server-csharp/src/lib/service.ts @@ -784,6 +784,7 @@ export async function $onEmit(context: EmitContext) usings: [], }; for (const [name, operation] of iface.operations) { + if (isTemplateDeclaration(operation)) continue; const doc = getDoc(this.emitter.getProgram(), operation); const returnTypes: Type[] = []; const [httpOp, _] = getHttpOperation(this.emitter.getProgram(), operation); @@ -1004,7 +1005,12 @@ export async function $onEmit(context: EmitContext) .checker.cloneType(responseType, { name: modelName }); responseType = returnedType; } - this.emitter.emitType(responseType); + // TemplateParameter types cannot be emitted (they are unresolved template placeholders). + // Template operations are filtered in interfaceDeclarationOperations, but this guard + // prevents crashes if a TemplateParameter response type is encountered via other paths. + if (responseType.kind !== "TemplateParameter") { + this.emitter.emitType(responseType); + } const context = this.emitter.getContext(); const result = getCSharpType(this.emitter.getProgram(), responseType, context.namespace); diff --git a/packages/http-server-csharp/test/generation.test.ts b/packages/http-server-csharp/test/generation.test.ts index 7f5c0175c66..df2d7201792 100644 --- a/packages/http-server-csharp/test/generation.test.ts +++ b/packages/http-server-csharp/test/generation.test.ts @@ -1245,6 +1245,23 @@ it("Handles user-defined model templates", async () => { ); }); +it("Handles template operations in interfaces without crashing", async () => { + // Regression test: interfaces with template operations should not crash with + // "Encountered type TemplateParameter which we don't know how to emit." + // Template operations (e.g. getItem(): T) should be skipped during emission. + await compileAndValidateMultiple( + tester, + ` + interface MyOps { + @get list(): string; + @get getItem(): T; + } + `, + [["IMyOps.cs", ["interface IMyOps", "Task ListAsync( );"]]], + [["IMyOps.cs", ["GetItemAsync"]]], + ); +}); + it("Handles void type in operations", async () => { await compileAndValidateMultiple( tester, From 1b31e9bf358862d10c0106a819a300af5716083c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 4 Mar 2026 20:20:29 +0000 Subject: [PATCH 3/3] chore: update changeset description per review feedback Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com> --- .../fix-http-server-csharp-template-parameter-2026-03-04.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.chronus/changes/fix-http-server-csharp-template-parameter-2026-03-04.md b/.chronus/changes/fix-http-server-csharp-template-parameter-2026-03-04.md index e6973995735..c574fda1eb7 100644 --- a/.chronus/changes/fix-http-server-csharp-template-parameter-2026-03-04.md +++ b/.chronus/changes/fix-http-server-csharp-template-parameter-2026-03-04.md @@ -4,4 +4,4 @@ packages: - "@typespec/http-server-csharp" --- -Fix crash when emitting interfaces that contain template operations. Template operations (e.g. `getItem(): T`) within interfaces no longer cause "Encountered type TemplateParameter which we don't know how to emit" error. +Fix crash when emitting interfaces that contain template operations. Template operations (e.g. `getItem(): T`) within interfaces will simply be skipped when emitting the interface.