Skip to content

Conversation

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented Oct 9, 2025

Backport of #120543 to release/10.0

/cc @jeffhandley @eiriktsarpalis

Customer Impact

  • Customer reported
  • Found internally

The Microsoft.Extensions.AI and Agent Framework libraries use [Experimental] attributes on APIs related to emerging AI concepts. We have found that System.Text.Json source-generated serialization code results references members and types that result in diagnostics--[Experimental], [Obsolete], and other such attributes can cause that behavior. Because the references are in generated code, suppressions cannot be applied at the call site--leading to the need for project-wide suppressions.

Project-wide suppressions on these diagnostics hide the fact that the customer is exposing non-stable APIs on their serialization model. Before this change, applying [JsonIgnore] to the types or members does not eliminate all references to the annotated APIs in the source-generated code, which is an unexpected behavior, and this still leaves the customer needing to apply project-wide suppressions.

With those project-wide suppressions in place, we cannot be confident that [Experimental] API names/shapes can be changed without catching consumers by surprise.

A customer encountered this issue while implementing a community contribution that involved the [Experimental] attribute in add support for background responses (dotnet/extensions#6854).

Fix

If the property is ignored and its type is not used anywhere else in the type graph, emit a JsonPropertyInfo of type 'object' to avoid unnecessarily referencing the type. STJ requires that all ignored properties be included so that it can perform necessary run-time validations using configuration not known at compile time such as the property naming policy and case sensitivity.

Regression

  • Yes
  • No

Testing

New tests were added to exercise the scenarios of where we expect diagnostics to be avoided, and testing was added to ensure diagnostics are still raised when an API is not marked as [JsonIgnore]. The tests illustrate the end-to-end AI scenarios are unblocked.

Risk

Medium. Any changes to System.Text.Json incur risk of affecting serialization, and changes to the source generator carry additional risk. These risks are mitigated by this being a very surgical fix that did not affect any existing tests.

@jeffhandley jeffhandley added this to the 10.0.0 milestone Oct 9, 2025
@jeffhandley jeffhandley self-assigned this Oct 9, 2025
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis
See info in area-owners.md if you want to be subscribed.

@jeffhandley jeffhandley requested a review from artl93 October 10, 2025 01:18
Copy link
Member

@artl93 artl93 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed for other work

@jeffhandley jeffhandley added the Servicing-consider Issue for next servicing release review label Oct 10, 2025
@artl93 artl93 added Servicing-approved Approved for servicing release and removed Servicing-consider Issue for next servicing release review labels Oct 11, 2025
@artl93 artl93 merged commit a402595 into release/10.0 Oct 11, 2025
98 of 105 checks passed
@akoeplinger akoeplinger deleted the backport/pr-120543-to-release/10.0 branch October 11, 2025 14:06
@github-actions github-actions bot locked and limited conversation to collaborators Nov 11, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-System.Text.Json Servicing-approved Approved for servicing release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants