If you're upgrading to the latest version of the Copilot SDK beta, there's a syntax change you need to know about. The .On() method now requires a generic type parameter. As the SDK is still in beta, breaking changes are not unexpected. But this one should be handled with extra care to avoid resource leaks. This post walks you through what changed, why it matters, and how to update your code. What changed In previous versions of the SDK, registering an event handler looked something like this: // Old syntax app.On(evt => { if (ev is AssistantMessageDeltaEvent deltaEvent) { Console.Write(deltaEvent.Data.DeltaContent); }); }
In the latest version, the .On() method is now generic. You must explicitly specify the activity or event type you're handling:
// New syntax using var subscription = app.On<AssistantMessageDeltaEvent>(evt => { Console.Write(deltaEvent.Data.DeltaContent); });
The method signature has changed from:...
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 o...