Skip to content

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

@aaronpowell

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;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions