Skip to content

fix: prevent crash when package-name option is missing in http-client-csharp#10315

Merged
JonathanCrd merged 3 commits into
microsoft:mainfrom
JonathanCrd:fix/csharp-no-options-crash-9554
Apr 9, 2026
Merged

fix: prevent crash when package-name option is missing in http-client-csharp#10315
JonathanCrd merged 3 commits into
microsoft:mainfrom
JonathanCrd:fix/csharp-no-options-crash-9554

Conversation

@JonathanCrd

Copy link
Copy Markdown
Member

Problem

When running the C# emitter with no options (specifically no package-name), the C# generator crashes with an InvalidOperationException instead of reporting a diagnostic or using a default.

Changes

C# Generator

  • Configuration.cs: Made package-name optional with a DefaultPackageName fallback ("GeneratedClient"). Removed ReadRequiredStringOption since no options are required anymore.
  • CodeModelGenerator.cs: In Configure(), resolves the default from PrimaryNamespace (code model namespace) and emits an info message — per Josh's suggestion.

TypeScript Emitter

  • emitter.ts: Generator failures now report diagnostics via sdkContext.logger.error() instead of throwing unhandled exceptions.

Tests

  • Updated ConfigurationTests.cs: verify default package name behavior and PrimaryNamespace resolution.
  • Added emitter test: verify generator failure reports diagnostic without crashing.

Fixes #9554


🤖 Created with JonathanCrd copilot

@JonathanCrd JonathanCrd self-assigned this Apr 9, 2026
@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 9, 2026
…-csharp

- Make package-name optional in C# Configuration with default fallback
- Resolve default from PrimaryNamespace in Configure() with info message
- Report diagnostics instead of throwing when C# generator fails
- Remove ReadRequiredStringOption since no options are required anymore
- Add tests for default package name behavior and diagnostic reporting

Fixes microsoft#9554

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@JonathanCrd JonathanCrd force-pushed the fix/csharp-no-options-crash-9554 branch from ae26f13 to c9ce8b6 Compare April 9, 2026 01:20
@pkg-pr-new

pkg-pr-new Bot commented Apr 9, 2026

Copy link
Copy Markdown

Open in StackBlitz

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

commit: be7d23a

@github-actions

github-actions Bot commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

No changes needing a change description found.

JonathanCrd and others added 2 commits April 8, 2026 18:51
@JonathanCrd JonathanCrd enabled auto-merge April 9, 2026 02:05
@JonathanCrd JonathanCrd added this pull request to the merge queue Apr 9, 2026
Merged via the queue into microsoft:main with commit 7365e39 Apr 9, 2026
29 checks passed
@JonathanCrd JonathanCrd deleted the fix/csharp-no-options-crash-9554 branch April 9, 2026 03:02
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 crash on no options

2 participants