After upgrading the GitHub Copilot SDK to the 1.0.0-beta.10 version, initiating the CopilotClient no longer worked. Instead I got the following error message:
System.Text.Json.JsonException: The JSON value could not be converted to System.DateTimeOffset. Path: $.timestamp | LineNumber: 0 | BytePositionInLine: 43. ---> System.InvalidOperationException: Cannot get the value of a token type 'Number' as a string. at System.Text.Json.ThrowHelper.ThrowInvalidOperationException_ExpectedString(JsonTokenType tokenType) at System.Text.Json.Utf8JsonReader.TryGetDateTimeOffset(DateTimeOffset& value) at System.Text.Json.Utf8JsonReader.GetDateTimeOffset() at System.Text.Json.Serialization.Converters.DateTimeOffsetConverter.Read(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options) at System.Text.Json.Serialization.Metadata.JsonPropertyInfo`1.ReadJsonAndSetMember(Object obj, ReadStack& state, Utf8JsonReader& reader) at System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value) at System.Text.Json.Serialization.Converters.JsonMetadataServicesConverter`1.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value) at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value, Boolean& isPopulatedValue) at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, T& value, JsonSerializerOptions options, ReadStack& state) --- End of inner exception stack trace --- at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack& state, Utf8JsonReader& reader, Exception ex) at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, T& value, JsonSerializerOptions options, ReadStack& state) at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.Deserialize(Utf8JsonReader& reader, ReadStack& state) at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.DeserializeAsObject(Utf8JsonReader& reader, ReadStack& state) at System.Text.Json.JsonSerializer.ReadFromSpanAsObject(ReadOnlySpan`1 utf8Json, JsonTypeInfo jsonTypeInfo, Nullable`1 actualByteCount) at System.Text.Json.JsonSerializer.Deserialize(JsonElement element, JsonTypeInfo jsonTypeInfo) at GitHub.Copilot.JsonRpc.InvokeAsync[T](String method, Object[] args, CancellationToken cancellationToken, Action`1 onResponseInline) at GitHub.Copilot.JsonRpc.InvokeAsync[T](String method, Object[] args, CancellationToken cancellationToken, Action`1 onResponseInline) at GitHub.Copilot.CopilotClient.InvokeRpcAsync[T](JsonRpc rpc, String method, Object[] args, StringBuilder stderrBuffer, CancellationToken cancellationToken, Action`1 onResponseInline) at GitHub.Copilot.CopilotClient.VerifyProtocolVersionAsync(Connection connection, CancellationToken cancellationToken) at GitHub.Copilot.CopilotClient.g__StartCoreAsync|24_0(CancellationToken ct) at GitHub.Copilot.CopilotClient.g__StartCoreAsync|24_0(CancellationToken ct) at GitHub.Copilot.CopilotClient.CreateSessionAsync(SessionConfig config, CancellationToken cancellationToken) at PowerPilot.Agents.ChatAgentService.GetOrCreateSessionAsync(CancellationToken ct) in D:\Projects\PowerPilot\src\PowerPilot.Agents\ChatAgentService.cs:line 161 at PowerPilot.Agents.ChatAgentService.ChatAsync(String userMessage, CancellationToken cancellationToken)+MoveNext() in D:\Projects\PowerPilot\src\PowerPilot.Agents\ChatAgentService.cs:line 85
I was using the default CopilotClient object which uses the included Copilot CLI and spawns it up as a child process.
The workaround
My first solution was more a workaround. I changed the code to use an already running Copilot CLI instance that was using the headless mode:
copilot --headless
I updated the CopilotClient to use this instance:
var clientOptions = new CopilotClientOptions();
if (!string.IsNullOrEmpty(options.CliUrl))
{
clientOptions.Connection = RuntimeConnection.ForUri(options.CliUrl);
}
return new CopilotClient(clientOptions);
When making this stitch, the error disappeared at least my application was working again. Of course, this is not a final solution. But this gives us a clue that the problem is probably related with the integrated Copilot CLI.
The solution
We accidently found a solution by upgrading our application to .NET 10. At the moment we encountered the error, the app was still using .NET 8. But after doing the upgrade, the issue disappeared.
Could it be that their was a problem with the .NET 8 version of the latest SDK?
I created a minimal example to reproduce the issue. However when I ran the .NET 8 version of this minimal example, it just worked.
Than I noticed the following in the output:
1>------ Build started: Project: CopilotSDKIssueNET810, Configuration: Debug Any CPU ------ 1>C:\Program Files\dotnet\sdk\10.0.300-preview.0.26177.108\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.RuntimeIdentifierInference.targets(383,5): message NETSDK1057: You are using a preview version of .NET. See: https://aka.ms/dotnet-support-policy 1> Downloading Copilot CLI 1.0.56-1 for win32-x64... 1> Downloading from "https://registry.npmjs.org/@github/copilot-win32-x64/-/copilot-win32-x64-1.0.56-1.tgz" to "D:\Projects\Test\CopilotSDKIssueNET810\CopilotSDKIssueNET810\obj\Debug\net8.0\copilot-cli\1.0.56-1\win32-x64\copilot.tgz" (84859620 bytes). 1> Skipping analyzers to speed up the build. You can execute 'Build' or 'Rebuild' command to run analyzers.
Aha! When updating the Copilot SDK package to the latest beta version, I assume it didn't update the corresponding CLI version. So that could be a valid reason.
As it is working now, I decided to leave it there. If the issue reappears, I’ll update this post.
Case closed…