Make the .NET library NativeAOT compatible#81
Merged
SteveSandersonMS merged 3 commits intogithub:mainfrom Jan 22, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
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.
agocke
approved these changes
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
924ed04 to
bf6da25
Compare
SteveSandersonMS
approved these changes
Jan 22, 2026
Contributor
SteveSandersonMS
left a comment
There was a problem hiding this comment.
Thanks, this looks great!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
<autogenerated/>from the source generated code, as it was suppressing the analyzers