Skip to content

Fix system model base provider resolution - #11585

Open
Wei Hu (live1206) wants to merge 1 commit into
microsoft:mainfrom
live1206:fix/system-object-base-provider
Open

Fix system model base provider resolution#11585
Wei Hu (live1206) wants to merge 1 commit into
microsoft:mainfrom
live1206:fix/system-object-base-provider

Conversation

@live1206

@live1206 Wei Hu (live1206) commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Ensure MTG creates and resolves the corresponding input base model provider when a SystemObjectModelProvider wraps a framework type with an existing CLR base type.

SystemObjectModelProvider.BuildBaseType() prefers SystemType.BaseType, so the normal ModelProvider.BuildBaseType() path does not create the declared TypeSpec base model. BuildBaseModelProvider() previously only checked CSharpTypeMap, which could leave the base provider null depending on model creation order.

The fallback now:

  • Creates the declared input base model when no mapped provider exists.
  • Verifies that its generated type matches the resolved base type by name.
  • Registers the resolved CSharpType alias for subsequent lookups.

Added a regression test using ArgumentException and SystemException to cover both automatic system base-provider creation and framework/non-framework CSharpType equivalence.

Contributes to #10787.

Validation

  • SystemObjectModelProviderTests: 27 passed
  • Full npm run test:generator
  • Azure management generator with local MTG project references and its base-provider visitor workaround removed:
    • 269 management generator tests passed
    • Full management test-project regeneration passed, including Mgmt-TypeSpec-MultiService

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@pkg-pr-new

pkg-pr-new Bot commented Aug 7, 2026

Copy link
Copy Markdown

Open in StackBlitz

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

commit: 723f8df

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

No changes needing a change description found.

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 fixes base model provider resolution for SystemObjectModelProvider when the wrapped framework type has an existing CLR base type, ensuring the corresponding declared TypeSpec base model provider is created/resolved and registered for subsequent lookups.

Changes:

  • Updates ModelProvider.BuildBaseModelProvider() to fall back to creating the declared input base model provider when no mapped provider exists for the resolved CLR base type, and to register a CSharpTypeMap alias when the types match by name.
  • Adds a regression test covering automatic system base-provider creation across an input model hierarchy (ArgumentException / SystemException).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Providers/ModelProvider.cs Adds a fallback that creates the declared input base model provider and aliases the resolved CLR base CSharpType to it when they match by name.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/SystemObjectModelProviderTests.cs Adds a regression test verifying base system providers are created/resolved from the input model inheritance chain.

@live1206

Copy link
Copy Markdown
Contributor Author

regen: Azure/azure-sdk-for-net#61816

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.

4 participants