Skip to content

File Based C# apps aren't supported by the SDK #53

Closed

Description

@aaronpowell

If we take the sample from the .NET README and turn it into a File Based app it errors due to the way the JSON serializer is configured on the RCP connection:

Unhandled exception. System.Text.Json.JsonException: An error occured during serialization.
 ---> System.InvalidOperationException: Reflection-based serialization has been disabled for this application. Either use the source generator APIs or explicitly configure the 'JsonSerializerOptions.TypeInfoResolver' property.
   at System.Text.Json.ThrowHelper.ThrowInvalidOperationException_JsonSerializerIsReflectionDisabled()
   at System.Text.Json.JsonSerializerOptions.ConfigureForJsonSerializer()
   at System.Text.Json.JsonSerializer.GetTypeInfo(JsonSerializerOptions options, Type inputType)
   at System.Text.Json.JsonSerializer.GetTypeInfo[T](JsonSerializerOptions options)
   at StreamJsonRpc.SystemTextJsonFormatter.<Serialize>g__WriteUserData|17_5(Object value, Type declaredType, <>c__DisplayClass17_0&, <>c__DisplayClass17_1&)
   at StreamJsonRpc.SystemTextJsonFormatter.<Serialize>g__WriteArguments|17_2(JsonRpcRequest request, <>c__DisplayClass17_0&, <>c__DisplayClass17_1&)
   at StreamJsonRpc.SystemTextJsonFormatter.Serialize(IBufferWriter`1 bufferWriter, JsonRpcMessage message)
   --- End of inner exception stack trace ---
   at StreamJsonRpc.SystemTextJsonFormatter.Serialize(IBufferWriter`1 bufferWriter, JsonRpcMessage message)
   at StreamJsonRpc.HeaderDelimitedMessageHandler.Write(JsonRpcMessage content, CancellationToken cancellationToken)
   at StreamJsonRpc.PipeMessageHandler.WriteCoreAsync(JsonRpcMessage content, CancellationToken cancellationToken)
   at StreamJsonRpc.MessageHandlerBase.WriteAsync(JsonRpcMessage content, CancellationToken cancellationToken)
   at StreamJsonRpc.JsonRpc.SendAsync(JsonRpcMessage message, CancellationToken cancellationToken)
   at StreamJsonRpc.JsonRpc.InvokeCoreAsync(JsonRpcRequest request, Type expectedResultType, CancellationToken cancellationToken)
   at StreamJsonRpc.JsonRpc.InvokeCoreAsync[TResult](RequestId id, String targetName, IReadOnlyList`1 arguments, IReadOnlyList`1 positionalArgumentDeclaredTypes, IReadOnlyDictionary`2 namedArgumentDeclaredTypes, CancellationToken cancellationToken, Boolean isParameterObject)
   at GitHub.Copilot.SDK.CopilotClient.VerifyProtocolVersionAsync(Connection connection, CancellationToken cancellationToken)
   at GitHub.Copilot.SDK.CopilotClient.<StartAsync>g__StartCoreAsync|9_0(CancellationToken ct)
   at GitHub.Copilot.SDK.CopilotClient.CleanupConnectionAsync(List`1 errors)
   at GitHub.Copilot.SDK.CopilotClient.ForceStopAsync()
   at GitHub.Copilot.SDK.CopilotClient.DisposeAsync()
   at Program.<Main>$(String[] args) in D:\tmp\copilot-sdk-playground.cs:line 32
   at Program.<Main>(String[] args)

The only change to the sample from the README is to add the package directive:

#:package GitHub.Copilot.SDK@*

using GitHub.Copilot.SDK;

// Create and start client
await using var client = new CopilotClient();
await client.StartAsync();

// Create a session
await using var session = await client.CreateSessionAsync(new SessionConfig
{
    Model = "gpt-5"
});

// Wait for response using session.idle event
var done = new TaskCompletionSource();

session.On(evt =>
{
    if (evt is AssistantMessageEvent msg)
    {
        Console.WriteLine(msg.Data.Content);
    }
    else if (evt is SessionIdleEvent)
    {
        done.SetResult();
    }
});

// Send a message and wait for completion
await session.SendAsync(new MessageOptions { Prompt = "What is 2+2?" });
await done.Task;

Activity

  1. aaronpowell commented on Jan 20, 2026

    @aaronpowell
    ContributorAuthor

    I believe it's some changes in https://github.com/github/copilot-sdk/blob/main/dotnet/src/Client.cs#L718-L729 that need to be done to support the serialization

  2. SteveSandersonMS commented on Jan 20, 2026

    @SteveSandersonMS
    Contributor

    Yes, some changes to JsonSerializerOptions or similar will be needed.

    For others reading, @aaronpowell and I discussed and he's going to look into it soon.

  3. stephentoub commented on Jan 22, 2026

    @stephentoub
    Collaborator

    This should be addressed by #81. @aaronpowell, can you confirm the problems go away with a new build containing that change?

  4. SteveSandersonMS commented on Jan 22, 2026

    @SteveSandersonMS
    Contributor

    Published a build with NativeAOT support: 0.1.16-preview.0

    Thanks to @stephentoub for implementing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions