Skip to content

fix(http-server-csharp): emitter type errors - #11628

Draft
sophia-ramsey wants to merge 11 commits into
mainfrom
sramsey/csharp-server-nullable
Draft

fix(http-server-csharp): emitter type errors#11628
sophia-ramsey wants to merge 11 commits into
mainfrom
sramsey/csharp-server-nullable

Conversation

@sophia-ramsey

@sophia-ramsey sophia-ramsey commented Aug 11, 2026

Copy link
Copy Markdown
Member

Addresses errors I encountered while using the C# server emitter to emit code from the ai foundry spec for the agent contracts api service package. Includes tests

Issues addressed:

  • duplicate nullable suffixes: fixed optional nullable value parameters emitting invalid C# types by ensuring nullable suffixes are applied only once (int?? to int?)
  • multipart content: fixed multipart operations emitting <Unresolved Symbol ...> by falling back to the original @multipartBody metadata when canonicalization data is unavailable
  • record parameter fixes: fixed error-model constructors emitting incompatible types such as Record, Array, or object instead of the same concrete structured types used by their properties
  • parameter ordering fix: fixed controller calls passing positional arguments in a different order than their business-interface signatures while preserving positional syntax for existing generated code
  • void as a success type: fixed void | @error responses generating invalid result assignments by excluding error branches from success-response analysis and emitting direct awaits with NoContent()

@pkg-pr-new

pkg-pr-new Bot commented Aug 11, 2026

Copy link
Copy Markdown

Open in StackBlitz

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

commit: f769da2

@github-actions

github-actions Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • @typespec/http-server-csharp
Show changes

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

fix errors in emitter including duplicate nullable suffixes, unresolved symbols for multipart content, incompatible types, parameter ordering, and void as a success type

@sophia-ramsey
sophia-ramsey requested a lite review from Copilot August 12, 2026 20:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves the C# HTTP server emitter’s correctness around nullable/optional parameter rendering, response handling for union return types (especially void | @error patterns), and controller argument ordering by tracking the original (business) operation behind each canonicalized HTTP operation.

Changes:

  • Fixes “double nullable” (int??) emission for optional nullable value-type parameters across interfaces and mocks.
  • Tracks canonical operation → source operation to preserve business-parameter ordering when generating controller call sites.
  • Improves response analysis to emit 204 NoContent (and NoContent()) for void success unions while still handling value success unions correctly; adds multipart and error-model-related robustness tests.

Reviewed changes

Copilot reviewed 20 out of 21 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/http-server-csharp/test/snapshots/sample-service/generated/controllers/PetsController.cs Updates generated DELETE action to return 204/NoContent for void success.
packages/http-server-csharp/test/nullable-parameters.test.ts Adds integration-style test to prevent int??/Choice?? in emitted mocks/interfaces.
packages/http-server-csharp/src/service-resolution.ts Returns both canonical ops map and a canonical→source operation map.
packages/http-server-csharp/src/service-resolution.test.ts Verifies canonical→source operation tracking behavior.
packages/http-server-csharp/src/emitter.tsx Plumbs canonical→source operation map via a new Alloy context provider.
packages/http-server-csharp/src/context/operation-source-context.ts Introduces OperationSources context for canonical→source operation lookup.
packages/http-server-csharp/src/components/type-expression/type-expression.tsx Adds helper to detect nullable value-type unions for correct T? emission.
packages/http-server-csharp/src/components/scaffolding/mock-implementations.tsx Aligns mock signatures with nullable/optional rules and multipart fallback detection.
packages/http-server-csharp/src/components/render-root.tsx Adds multipart fallback detection for interface usings when canonical metadata is absent.
packages/http-server-csharp/src/components/multipart-fallback.test.tsx New test ensuring multipart interface + mocks stay aligned without canonicalization.
packages/http-server-csharp/src/components/models/models.tsx Adjusts JsonNodes-using decision for root error models (includes inherited checks).
packages/http-server-csharp/src/components/models/model-helpers.ts Improves modelNeedsJsonNodes recursion/inheritance handling.
packages/http-server-csharp/src/components/models/error-models.tsx Uses TypeExpression for union/tuple/record/array ctor parameter typing.
packages/http-server-csharp/src/components/models/error-models.test.tsx Adds tests for structured error constructor typing + inherited JsonNodes using.
packages/http-server-csharp/src/components/interfaces/interfaces.tsx Fixes nullable suffix emission; adds multipart decorator fallback helpers.
packages/http-server-csharp/src/components/interfaces/interfaces.test.tsx Adds tests for nullable suffix and multipart fallback behavior.
packages/http-server-csharp/src/components/controllers/controllers.tsx Passes source (business) operation into ControllerAction via context lookup.
packages/http-server-csharp/src/components/controllers/controllers.test.tsx Adds test ensuring source operation preserves positional argument order.
packages/http-server-csharp/src/components/controller-action/response-analysis.ts Updates success-status analysis for unions (skip errors, handle void success → 204).
packages/http-server-csharp/src/components/controller-action/controller-action.tsx Orders call arguments based on source operation; uses updated success-status analysis.
packages/http-server-csharp/src/components/controller-action/controller-action.test.tsx Adds regression tests for void/value union handling and call-arg ordering.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread packages/http-server-csharp/src/context/operation-source-context.ts
@sophia-ramsey sophia-ramsey changed the title Sramsey/csharp server nullable fix(http-server-csharp): emitter type errors Aug 12, 2026
@azure-sdk-automation

azure-sdk-automation Bot commented Aug 12, 2026

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants