Skip to content

Fix C# generated attribute back compatibility#11364

Closed
live1206 wants to merge 7 commits into
microsoft:mainfrom
live1206:fix/csharp-preserve-ga-generated-attributes
Closed

Fix C# generated attribute back compatibility#11364
live1206 wants to merge 7 commits into
microsoft:mainfrom
live1206:fix/csharp-preserve-ga-generated-attributes

Conversation

@live1206

@live1206 live1206 commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add an opt-in, write-time TypeProvider hook for emitting selected attributes from the previous GA contract without placing them in the normal attribute/visitor/reference-map pipeline
  • preserve prior ModelReaderWriterBuildableAttribute entries only when their target and every enclosing type and generic argument remain emitted or otherwise resolvable, while deduplicating entries still generated today
  • exclude unrelated attributes such as EditorBrowsableAttribute, removed targets, and any target component marked error-obsolete (Obsolete(..., true))
  • recursively collect, deduplicate, and reapply every obsolete and experimental diagnostic suppression required by the target, its declaring types, and its generic arguments
  • correctly resolve and render arbitrarily nested target types, including constructed generic declaring types

Validation

  • npm run build
  • 1,719 Microsoft.TypeSpec.Generator tests
  • 1,514 Microsoft.TypeSpec.Generator.ClientModel tests
  • npm run cop
  • full C# test-library regeneration
  • pnpm format:check
  • type-aware oxlint

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

Copilot-Session: e373c6e0-590e-41ec-9a11-eeb70cec72d4
@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 Jul 23, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jul 23, 2026

Copy link
Copy Markdown

Open in StackBlitz

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

commit: 28da475

@github-actions

Copy link
Copy Markdown
Contributor

No changes needing a change description found.

live1206 added 2 commits July 23, 2026 06:49
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: e373c6e0-590e-41ec-9a11-eeb70cec72d4
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: e373c6e0-590e-41ec-9a11-eeb70cec72d4
@live1206 live1206 closed this Jul 23, 2026
@live1206 live1206 reopened this Jul 23, 2026
live1206 added 4 commits July 23, 2026 08:37
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: e373c6e0-590e-41ec-9a11-eeb70cec72d4
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: e373c6e0-590e-41ec-9a11-eeb70cec72d4
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: e373c6e0-590e-41ec-9a11-eeb70cec72d4
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: e373c6e0-590e-41ec-9a11-eeb70cec72d4
@jorgerangel-msft

Copy link
Copy Markdown
Contributor

fyi, I was tackling this in #11237.

@JoshLove-msft

Copy link
Copy Markdown
Contributor

The nested generic type rendering fixes in CSharpType/CodeWriter make sense, but I don't think this compatibility fix needs three additional overridable TypeProvider hooks (MergeLastContractAttributesForWrite, ShouldPreserveLastContractAttributeForWrite, and BuildLastContractAttributeForWrite).

ModelReaderWriterContextDefinition is currently the only consumer, and its override effectively merges through base, filters the result, and then merges again. Could the preservation/filtering/suppression logic remain private in ModelReaderWriterContextDefinition, with the existing BuildAttributesForWrite override as the sole extension point? Unless we expect other providers to need exactly this write-time last-contract attribute pipeline, the new protected-internal API surface seems broader and more specialized than the fix requires.

--generated by Copilot

@live1206 live1206 closed this Jul 24, 2026
@live1206
live1206 deleted the fix/csharp-preserve-ga-generated-attributes branch July 24, 2026 00:33
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