Skip to content

fix(http-client-csharp): exclude custom constructors with settings parameter from property discovery#10260

Merged
JoshLove-msft merged 4 commits intomicrosoft:mainfrom
JoshLove-msft:fix/settings-self-reference
Apr 3, 2026
Merged

fix(http-client-csharp): exclude custom constructors with settings parameter from property discovery#10260
JoshLove-msft merged 4 commits intomicrosoft:mainfrom
JoshLove-msft:fix/settings-self-reference

Conversation

@JoshLove-msft
Copy link
Copy Markdown
Contributor

@JoshLove-msft JoshLove-msft commented Apr 3, 2026

Problem

When building settings properties from custom constructors, we consider all public constructors on the client. If a custom constructor takes the client's settings type as a parameter, it doesn't make sense to consider that constructor — the settings type is the thing we're building, so its constructor parameters aren't meaningful inputs for configuration binding.

Fix

Skip custom constructors that have a parameter whose type matches \ClientProvider.ClientSettings.Type\ when discovering parameters for settings properties, \BindCore\ bindings, and \ConfigurationSchema.json\ generation.

…ings properties

Replace name-based 'settings' filter with type-based check that
compares the parameter's resolved type name against the settings
type name. This correctly excludes parameters whose type matches
the ClientSettings type itself, preventing self-referential
Settings properties regardless of parameter naming.

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

pkg-pr-new Bot commented Apr 3, 2026

Open in StackBlitz

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

commit: 64ad5ed

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 3, 2026

No changes needing a change description found.

JoshLove-msft and others added 3 commits April 2, 2026 21:02
…eter

When discovering custom constructor parameters for ClientSettings
properties and ConfigurationSchema.json, skip constructors that have
a ClientSettings-typed parameter. These are generated settings
constructors (e.g. Client(ClientSettings settings)) that appear in
CustomCodeView because Roslyn sees all partial class members. Including
their parameters creates a self-referential Settings property on the
settings type.

Added HasSettingsParameter helper and tests verifying settings types
don't contain self-referential properties or bindings.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…eter

When discovering custom constructor parameters for ClientSettings
properties, BindCore binding, and ConfigurationSchema.json, skip
constructors that have a parameter matching the client's settings type.

The generated settings constructor (e.g. Client(ClientSettings settings))
is visible through CustomCodeView because Roslyn sees all partial class
members. Including its parameter creates a self-referential Settings
property on the settings type.

The fix checks parameter type equality against ClientProvider.ClientSettings.Type
rather than using name-based heuristics.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@JoshLove-msft JoshLove-msft changed the title fix(http-client-csharp): filter settings-typed params from ClientSett… fix(http-client-csharp): skip settings constructor when discovering custom constructor parameters Apr 3, 2026
@JoshLove-msft JoshLove-msft changed the title fix(http-client-csharp): skip settings constructor when discovering custom constructor parameters fix(http-client-csharp): skip custom constructors with settings parameter in ClientSettings discovery Apr 3, 2026
@JoshLove-msft JoshLove-msft changed the title fix(http-client-csharp): skip custom constructors with settings parameter in ClientSettings discovery fix(http-client-csharp): exclude custom constructors with settings parameter from property discovery Apr 3, 2026
@JoshLove-msft JoshLove-msft added this pull request to the merge queue Apr 3, 2026
Merged via the queue into microsoft:main with commit ce6ef84 Apr 3, 2026
29 checks passed
@JoshLove-msft JoshLove-msft deleted the fix/settings-self-reference branch April 3, 2026 17:15
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.

3 participants