Skip to content

Use STJ source generation in Cli backchannel #9993

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 23, 2025

Conversation

eerhardt
Copy link
Member

Description

This sets us up for being AOT compatible once the build system is able to build for AOT on all platforms.

Contributes to #8677

FYI @AArnott

Checklist

  • Is this feature complete?
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • No
  • Did you add public API?
    • No
  • Does the change make any security assumptions or guarantees?
    • No
  • Does the change require an update in our Aspire docs?
    • No

This sets us up for being AOT compatible once the build system is able to build for AOT on all platforms.

Contributes to dotnet#8677
Copy link
Contributor

@Copilot Copilot AI left a comment

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 integrates System.Text.Json source generation into the CLI backchannel to prepare for future AOT compatibility.

  • Extracts formatter creation into CreateMessageFormatter() and applies source-generated JSON metadata
  • Suppresses reflection/AOT analysis warnings for the new formatter
  • Disables reflection-based JSON by default in the CLI project file and pins an alpha StreamJsonRpc version

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/Aspire.Cli/Backchannel/AppHostBackchannel.cs Replaced inline SystemTextJsonFormatter with CreateMessageFormatter(), added suppression attributes, and introduced SourceGenerationContext
src/Aspire.Cli/Aspire.Cli.csproj Set JsonSerializerIsReflectionEnabledByDefault to false, commented out PublishAot, and updated StreamJsonRpc package reference
Comments suppressed due to low confidence (3)

src/Aspire.Cli/Backchannel/AppHostBackchannel.cs:153

  • Consider adding an XML doc comment on CreateMessageFormatter to explain its purpose and the rationale for the suppression attributes, improving maintainability and discoverability.
    private static SystemTextJsonFormatter CreateMessageFormatter()

src/Aspire.Cli/Backchannel/AppHostBackchannel.cs:198

  • Add unit or integration tests that serialize and deserialize expected backchannel messages using this SourceGenerationContext to guard against future regressions in the AOT scenario.
[JsonSerializable(typeof(string[]))]

src/Aspire.Cli/Backchannel/AppHostBackchannel.cs:206

  • [nitpick] The name SourceGenerationContext is very generic; consider renaming it to something more descriptive (e.g., CliBackchannelJsonContext) to avoid collisions and clarify its scope.
internal partial class SourceGenerationContext : JsonSerializerContext;

@eerhardt eerhardt merged commit 5cc5265 into dotnet:main Jun 23, 2025
252 checks passed
@eerhardt eerhardt deleted the NativeAOT_CLI branch June 23, 2025 21:49
@github-actions github-actions bot locked and limited conversation to collaborators Jul 24, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants