Skip to content

Explain unresolved C# @alternateType mappings - #12620

Draft
Jorge Rangel (jorgerangel-msft) wants to merge 2 commits into
mainfrom
copilot/improve-diagnostic-alternativetype
Draft

Jorge Rangel (jorgerangel-msft) wants to merge 2 commits into
mainfrom
copilot/improve-diagnostic-alternativetype

Conversation

@jorgerangel-msft

@jorgerangel-msft Jorge Rangel (jorgerangel-msft) commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

The C# generator’s warning didn’t explain why an @alternateType target available only through a ProjectReference could not be resolved. The generator needs a versioned NuGet package reference for that lookup.

  • Missing package metadata: The warning tells users to specify the NuGet package ID in @alternateType.
  • Missing package assembly: The warning names the target type, package, and minimum version when supplied. It explains why a ProjectReference alone is insufficient and points to a versioned PackageReference or a central package version override.

The unsupported-external-type warning code and resolution behavior are unchanged.

warning unsupported-external-type: External type 'Test.Referenced.Project.Class1' could not be resolved:
no assembly was found in the project's resolved dependencies for NuGet package 'Test.Referenced.Project' (>= 2.0.0).
A ProjectReference alone cannot resolve @alternateType. Use a versioned NuGet PackageReference and,
if versions are managed centrally, set the version there (for example, in a package override).

Co-authored-by: copilot-swe-agent[bot] <198982749+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 Nov 19, 2026
@jorgerangel-msft Jorge Rangel (jorgerangel-msft) changed the title [WIP] Improve diagnostic when alternativeType is not resolved Explain unresolved C# @alternateType mappings Nov 19, 2026
@pkg-pr-new

pkg-pr-new Bot commented Nov 19, 2026

Copy link
Copy Markdown

Open in StackBlitz

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

commit: dd977d1

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.

🟢 Approval recommended

No active review issues remain in the changes clarifying C# dependency warnings and updating related diagnostic tests.

No open issues 🎉

What changed in this PR

Improves the C# generator’s unresolved @alternateType warnings to explain the NuGet dependency requirements behind issue #12616. The warning code and type-resolution behavior remain unchanged.

Changes:

  • Adds guidance on package IDs, versioned PackageReference entries, and centrally managed versions.
  • Clarifies missing-assembly diagnostics and normalizes warning punctuation.
  • Adds ProjectReference diagnostic tests and updates existing message assertions.
File Description
packages/​http-client-csharp/​generator/​Microsoft.TypeSpec.Generator/​test/​Utilities/​ExternalTypeReferenceResolverTests.cs Tests actionable warnings for ProjectReference-only dependencies and updates expected messages.
packages/​http-client-csharp/​generator/​Microsoft.TypeSpec.Generator/​src/​Utilities/​ExternalTypeReferenceResolver.cs Adds shared package-reference guidance and clearer missing-assembly details.
packages/​http-client-csharp/​generator/​Microsoft.TypeSpec.Generator/​src/​TypeFactory.cs Explains missing package metadata and ensures consistent final punctuation.

Review effort: Balanced

@github-actions

Copy link
Copy Markdown
Contributor

No changes needing a change description found.

This branch has not been deployed

No deployments
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.

Improve Diagnostic When alternativeType is Not resolved

3 participants