fix(dotnet): Add AOT-safe SetForegroundSessionRequest for SetForegroundSessionIdAsync()#1144
Merged
stephentoub merged 1 commit intogithub:mainfrom Apr 27, 2026
Conversation
…roundSessionIdAsync()`
- Replace the anonymous `new { sessionId }` with `new SetForegroundSessionRequest(sessionId)`
This fixes the runtime `System.Text.Json` metadata failure when `SetForegroundSessionIdAsync()` is used with source-generated serialization.
jeremiahjordanisaacson
added a commit
to jeremiahjordanisaacson/copilot-sdk-supercharged
that referenced
this pull request
Apr 27, 2026
…ndSessionIdAsync()
Replace the anonymous `new { sessionId }` with `new SetForegroundSessionRequest(sessionId)`
to fix the runtime System.Text.Json metadata failure when SetForegroundSessionIdAsync() is
used with source-generated serialization.
Upstream: github#1144 (c63feb2)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
jeremiahjordanisaacson
added a commit
to jeremiahjordanisaacson/copilot-sdk-supercharged
that referenced
this pull request
Apr 28, 2026
…ndSessionIdAsync()
Replace the anonymous `new { sessionId }` with `new SetForegroundSessionRequest(sessionId)`
to fix the runtime System.Text.Json metadata failure when SetForegroundSessionIdAsync() is
used with source-generated serialization.
Upstream: github#1144 (c63feb2)
jeremiahjordanisaacson
pushed a commit
to jeremiahjordanisaacson/copilot-sdk-supercharged
that referenced
this pull request
Apr 28, 2026
…roundSessionIdAsync()` (github#1144) - Replace the anonymous `new { sessionId }` with `new SetForegroundSessionRequest(sessionId)` This fixes the runtime `System.Text.Json` metadata failure when `SetForegroundSessionIdAsync()` is used with source-generated serialization.
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.
Current State
The current code in
SetForegroundSessionIdAsync(), used to set the terminal foreground session ID, is not AOT-safe.The code uses an anonymous type
new { sessionId }to construct the request:That anonymous type is not registered in
ClientJsonContext, so this will fail at runtime before the RPC is sent.Fix/Changes
This can be updated to use a new source-generated
SetForegroundSessionRequest:Other functions do this too:
With the necessary JSON attribute and constructor, following the patterns of the surrounding code:
Testing
Made the change locally and verified that it now works as expected with no error, correctly switching the terminal to the correct session.
Context
I did see in
CONTRIBUTING.mdthat there should be a link to an issue, but I just encountered this bug and the fix is both small, and has surrounding code matching it.Error
The error is below, but also find attached a simple
dotnet runscript to reproduce the error:PR_SetForegroundSessionRequest.cs