8000 Make the .NET library NativeAOT compatible by stephentoub · Pull Request #81 · github/copilot-sdk · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@stephentoub
Copy link
Contributor
@stephentoub stephentoub commented Jan 21, 2026
  • Enabled AOT analyzers
  • Disabled STJ reflection in the test project (to help vet NAOT correctness)
  • Use source generation for all types that may be serialized
  • Remove all use of anonymous types
  • Removed <autogenerated/> from the source generated code, as it was suppressing the analyzers
  • Added support for propagating StreamJsonRpc's tracing to the CopilotClient's ILogger. I used this for debugging and decided to leave it
  • Updated StreamJsonRpc to a newly published version on nuget to pick up NativeAOT fixes
  • Cleaned up some formatting in the session types generator, in particular using a file-scoped namespace and removing the top-level indentation

@stephentoub stephentoub requested a review from a team as a code owner January 21, 2026 23:27
Copilot AI review requested due to automatic review settings January 21, 2026 23:27
8000 Copy link
Contributor
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

Updates the .NET SDK to be NativeAOT-friendly by removing reflection/anonymous-type usage in JSON paths and introducing System.Text.Json source generation for RPC + model types.

Changes:

  • Switch RPC + model serialization to STJ source-generated contexts and remove anonymous request objects.
  • Regenerate session event types with file-scoped namespace + source-gen JsonSerializerContext.
  • Update tests to disable STJ reflection and add test-only serializer contexts; bump StreamJsonRpc.

Reviewed changes

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

Show a summary per file
File Description
nodejs/scripts/generate-csharp-session-types.ts Updates the C# session-types generator to emit file-scoped namespace output and a source-gen JsonSerializerContext.
dotnet/test/ToolsTests.cs Passes explicit serializer options for tool invocation and adds a test JsonSerializerContext.
dotnet/test/Harness/CapiProxy.cs Replaces anonymous request payloads and switches HttpClient JSON calls to source-gen type info.
dotnet/test/GitHub.Copilot.SDK.Test.csproj Disables reflection-based STJ serialization to validate NativeAOT compatibility in tests.
dotnet/src/Types.cs Adds a TypesJsonContext with [JsonSerializable] entries for core SDK types (incl. Ping types).
dotnet/src/Session.cs Removes anonymous RPC payloads and adds SessionJsonContext for request/response types.
dotnet/src/GitHub.Copilot.SDK.csproj Marks the library as AOT compatible and updates StreamJsonRpc.
dotnet/src/Generated/SessionEvents.cs Regenerated session events with file-scoped namespace and a source-gen context.
dotnet/src/Client.cs Updates JsonRpc formatter setup for NativeAOT, removes attribute-based RPC target wiring, and adds trace forwarding to ILogger.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

stephentoub and others added 3 commits January 22, 2026 13:49
- Enabled AOT analyzers
- Disabled STJ reflection in the test project (to help vet NAOT correctness)
- Use source generation for all types that may be serialized
- Remove all use of anonymous types
- Removed <autogenerated/> from the source generated code, as it was suppressing the analyzers
- Added support for propagating StreamJsonRpc's tracing to the CopilotClient's ILogger. I used this for debugging and decided to leave it
- Updated StreamJsonRpc to a newly published version on nuget to pick up NativeAOT fixes
- Cleaned up some formatting in the session types generator, in particular using a file-scoped namespace and removing the top-level indentation
Copy link
Contributor
@SteveSandersonMS SteveSandersonMS left a comment

Choose a reason for hiding this comment

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

Thanks, this looks great!

@SteveSandersonMS SteveSandersonMS added this pull request to the merge queue Jan 22, 2026
Merged via the queue into github:main with commit 4e7319e Jan 22, 2026
0 of 12 checks passed
@stephentoub stephentoub deleted the naot branch January 22, 2026 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

0