From f1c75e22d7058f69f18219429d38a04dcca635a8 Mon Sep 17 00:00:00 2001 From: SergeyMenshykh Date: Fri, 30 Jan 2026 10:56:12 +0000 Subject: [PATCH 1/7] delete deserialize method of agent response --- .../SharedState/SharedStateAgent.cs | 16 ++- .../Server/SharedStateAgent.cs | 16 ++- .../Agent_Step05_StructuredOutput/Program.cs | 2 +- .../Program.cs | 2 +- .../08_WriterCriticWorkflow/Program.cs | 2 +- .../M365Agent/Agents/WeatherForecastAgent.cs | 16 ++- .../AgentResponse.cs | 121 ------------------ .../AgentResponseTests.cs | 118 +---------------- 8 files changed, 49 insertions(+), 244 deletions(-) diff --git a/dotnet/samples/AGUIClientServer/AGUIDojoServer/SharedState/SharedStateAgent.cs b/dotnet/samples/AGUIClientServer/AGUIDojoServer/SharedState/SharedStateAgent.cs index 51f4791272..96362a89a8 100644 --- a/dotnet/samples/AGUIClientServer/AGUIDojoServer/SharedState/SharedStateAgent.cs +++ b/dotnet/samples/AGUIClientServer/AGUIDojoServer/SharedState/SharedStateAgent.cs @@ -78,7 +78,7 @@ protected override async IAsyncEnumerable RunCoreStreamingA var response = allUpdates.ToAgentResponse(); - if (response.TryDeserialize(this._jsonSerializerOptions, out JsonElement stateSnapshot)) + if (TryDeserialize(response.Text, this._jsonSerializerOptions, out JsonElement stateSnapshot)) { byte[] stateBytes = JsonSerializer.SerializeToUtf8Bytes( stateSnapshot, @@ -103,4 +103,18 @@ protected override async IAsyncEnumerable RunCoreStreamingA yield return update; } } + + private static bool TryDeserialize(string json, JsonSerializerOptions jsonSerializerOptions, out T structuredOutput) + { + try + { + structuredOutput = JsonSerializer.Deserialize(json, jsonSerializerOptions)!; + return true; + } + catch + { + structuredOutput = default!; + return false; + } + } } diff --git a/dotnet/samples/GettingStarted/AGUI/Step05_StateManagement/Server/SharedStateAgent.cs b/dotnet/samples/GettingStarted/AGUI/Step05_StateManagement/Server/SharedStateAgent.cs index 66e8da6eed..015e945f75 100644 --- a/dotnet/samples/GettingStarted/AGUI/Step05_StateManagement/Server/SharedStateAgent.cs +++ b/dotnet/samples/GettingStarted/AGUI/Step05_StateManagement/Server/SharedStateAgent.cs @@ -107,7 +107,7 @@ stateObj is not JsonElement state || var response = allUpdates.ToAgentResponse(); // Try to deserialize the structured state response - if (response.TryDeserialize(this._jsonSerializerOptions, out JsonElement stateSnapshot)) + if (TryDeserialize(response.Text, this._jsonSerializerOptions, out JsonElement stateSnapshot)) { // Serialize and emit as STATE_SNAPSHOT via DataContent byte[] stateBytes = JsonSerializer.SerializeToUtf8Bytes( @@ -134,4 +134,18 @@ stateObj is not JsonElement state || yield return update; } } + + private static bool TryDeserialize(string json, JsonSerializerOptions jsonSerializerOptions, out T structuredOutput) + { + try + { + structuredOutput = JsonSerializer.Deserialize(json, jsonSerializerOptions)!; + return true; + } + catch + { + structuredOutput = default!; + return false; + } + } } diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step05_StructuredOutput/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step05_StructuredOutput/Program.cs index 38762ebfd1..78b3b749d8 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step05_StructuredOutput/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step05_StructuredOutput/Program.cs @@ -44,7 +44,7 @@ // Assemble all the parts of the streamed output, since we can only deserialize once we have the full json, // then deserialize the response into the PersonInfo class. -PersonInfo personInfo = (await updates.ToAgentResponseAsync()).Deserialize(JsonSerializerOptions.Web); +PersonInfo personInfo = JsonSerializer.Deserialize((await updates.ToAgentResponseAsync()).Text, JsonSerializerOptions.Web)!; Console.WriteLine("Assistant Output:"); Console.WriteLine($"Name: {personInfo.Name}"); diff --git a/dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step05_StructuredOutput/Program.cs b/dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step05_StructuredOutput/Program.cs index d252b82b1e..0b67105ed1 100644 --- a/dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step05_StructuredOutput/Program.cs +++ b/dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step05_StructuredOutput/Program.cs @@ -61,7 +61,7 @@ // Assemble all the parts of the streamed output, since we can only deserialize once we have the full json, // then deserialize the response into the PersonInfo class. -PersonInfo personInfo = (await updates.ToAgentResponseAsync()).Deserialize(JsonSerializerOptions.Web); +PersonInfo personInfo = JsonSerializer.Deserialize((await updates.ToAgentResponseAsync()).Text, JsonSerializerOptions.Web)!; Console.WriteLine("Assistant Output:"); Console.WriteLine($"Name: {personInfo.Name}"); diff --git a/dotnet/samples/GettingStarted/Workflows/_Foundational/08_WriterCriticWorkflow/Program.cs b/dotnet/samples/GettingStarted/Workflows/_Foundational/08_WriterCriticWorkflow/Program.cs index 5654b23baf..ebe3e24d41 100644 --- a/dotnet/samples/GettingStarted/Workflows/_Foundational/08_WriterCriticWorkflow/Program.cs +++ b/dotnet/samples/GettingStarted/Workflows/_Foundational/08_WriterCriticWorkflow/Program.cs @@ -327,7 +327,7 @@ public override async ValueTask HandleAsync( // Convert the stream to a response and deserialize the structured output AgentResponse response = await updates.ToAgentResponseAsync(cancellationToken); - CriticDecision decision = response.Deserialize(JsonSerializerOptions.Web); + CriticDecision decision = JsonSerializer.Deserialize(response.Text, JsonSerializerOptions.Web)!; Console.WriteLine($"Decision: {(decision.Approved ? "✅ APPROVED" : "❌ NEEDS REVISION")}"); if (!string.IsNullOrEmpty(decision.Feedback)) diff --git a/dotnet/samples/M365Agent/Agents/WeatherForecastAgent.cs b/dotnet/samples/M365Agent/Agents/WeatherForecastAgent.cs index 5968e4eb28..e10c5b65c1 100644 --- a/dotnet/samples/M365Agent/Agents/WeatherForecastAgent.cs +++ b/dotnet/samples/M365Agent/Agents/WeatherForecastAgent.cs @@ -54,7 +54,7 @@ protected override async Task RunCoreAsync(IEnumerable(JsonSerializerOptions.Web, out var structuredOutput)) + if (TryDeserialize(response.Text, JsonSerializerOptions.Web, out var structuredOutput)) { var textContentMessage = response.Messages.FirstOrDefault(x => x.Contents.OfType().Any()); if (textContentMessage is not null) @@ -112,4 +112,18 @@ private static AdaptiveCard CreateWeatherCard(string? location, string? conditio }); return card; } + + private static bool TryDeserialize(string json, JsonSerializerOptions jsonSerializerOptions, out T structuredOutput) + { + try + { + structuredOutput = JsonSerializer.Deserialize(json, jsonSerializerOptions)!; + return true; + } + catch + { + structuredOutput = default!; + return false; + } + } } diff --git a/dotnet/src/Microsoft.Agents.AI.Abstractions/AgentResponse.cs b/dotnet/src/Microsoft.Agents.AI.Abstractions/AgentResponse.cs index ba6068c554..e9cda50ad1 100644 --- a/dotnet/src/Microsoft.Agents.AI.Abstractions/AgentResponse.cs +++ b/dotnet/src/Microsoft.Agents.AI.Abstractions/AgentResponse.cs @@ -1,19 +1,11 @@ // Copyright (c) Microsoft. All rights reserved. using System; -#if NET -using System.Buffers; -#endif using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; -#if NET -using System.Text; -#endif -using System.Text.Json; using System.Text.Json.Serialization; -using System.Text.Json.Serialization.Metadata; using Microsoft.Shared.Diagnostics; using Microsoft.Extensions.AI; @@ -290,117 +282,4 @@ public AgentResponseUpdate[] ToAgentResponseUpdates() return updates; } - - /// - /// Deserializes the response text into the given type. - /// - /// The output type to deserialize into. - /// The result as the requested type. - /// The result is not parsable into the requested type. - public T Deserialize() => - this.Deserialize(AgentAbstractionsJsonUtilities.DefaultOptions); - - /// - /// Deserializes the response text into the given type using the specified serializer options. - /// - /// The output type to deserialize into. - /// The JSON serialization options to use. - /// The result as the requested type. - /// The result is not parsable into the requested type. - public T Deserialize(JsonSerializerOptions serializerOptions) - { - _ = Throw.IfNull(serializerOptions); - - var structuredOutput = this.GetResultCore(serializerOptions, out var failureReason); - return failureReason switch - { - FailureReason.ResultDidNotContainJson => throw new InvalidOperationException("The response did not contain JSON to be deserialized."), - FailureReason.DeserializationProducedNull => throw new InvalidOperationException("The deserialized response is null."), - _ => structuredOutput!, - }; - } - - /// - /// Tries to deserialize response text into the given type. - /// - /// The output type to deserialize into. - /// The parsed structured output. - /// if parsing was successful; otherwise, . - public bool TryDeserialize([NotNullWhen(true)] out T? structuredOutput) => - this.TryDeserialize(AgentAbstractionsJsonUtilities.DefaultOptions, out structuredOutput); - - /// - /// Tries to deserialize response text into the given type using the specified serializer options. - /// - /// The output type to deserialize into. - /// The JSON serialization options to use. - /// The parsed structured output. - /// if parsing was successful; otherwise, . - public bool TryDeserialize(JsonSerializerOptions serializerOptions, [NotNullWhen(true)] out T? structuredOutput) - { - _ = Throw.IfNull(serializerOptions); - - try - { - structuredOutput = this.GetResultCore(serializerOptions, out var failureReason); - return failureReason is null; - } - catch - { - structuredOutput = default; - return false; - } - } - - private static T? DeserializeFirstTopLevelObject(string json, JsonTypeInfo typeInfo) - { -#if NET - // We need to deserialize only the first top-level object as a workaround for a common LLM backend - // issue. GPT 3.5 Turbo commonly returns multiple top-level objects after doing a function call. - // See https://community.openai.com/t/2-json-objects-returned-when-using-function-calling-and-json-mode/574348 - var utf8ByteLength = Encoding.UTF8.GetByteCount(json); - var buffer = ArrayPool.Shared.Rent(utf8ByteLength); - try - { - var utf8SpanLength = Encoding.UTF8.GetBytes(json, 0, json.Length, buffer, 0); - var reader = new Utf8JsonReader(new ReadOnlySpan(buffer, 0, utf8SpanLength), new() { AllowMultipleValues = true }); - return JsonSerializer.Deserialize(ref reader, typeInfo); - } - finally - { - ArrayPool.Shared.Return(buffer); - } -#else - return JsonSerializer.Deserialize(json, typeInfo); -#endif - } - - private T? GetResultCore(JsonSerializerOptions serializerOptions, out FailureReason? failureReason) - { - var json = this.Text; - if (string.IsNullOrEmpty(json)) - { - failureReason = FailureReason.ResultDidNotContainJson; - return default; - } - - // If there's an exception here, we want it to propagate, since the Result property is meant to throw directly - - T? deserialized = DeserializeFirstTopLevelObject(json!, (JsonTypeInfo)serializerOptions.GetTypeInfo(typeof(T))); - - if (deserialized is null) - { - failureReason = FailureReason.DeserializationProducedNull; - return default; - } - - failureReason = default; - return deserialized; - } - - private enum FailureReason - { - ResultDidNotContainJson, - DeserializationProducedNull - } } diff --git a/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AgentResponseTests.cs b/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AgentResponseTests.cs index 75bc90ca8e..3208d64e57 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AgentResponseTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AgentResponseTests.cs @@ -214,30 +214,6 @@ public void ToAgentResponseUpdatesProducesUpdates() Assert.Equal(100, usageContent.Details.TotalTokenCount); } -#if NETFRAMEWORK - /// - /// Since Json Serialization using reflection is disabled in .net core builds, and we are using a custom type here that wouldn't - /// be registered with the default source generated serializer, this test will only pass in .net framework builds where reflection-based - /// serialization is available. - /// - [Fact] - public void ParseAsStructuredOutputSuccess() - { - // Arrange. - var expectedResult = new Animal { Id = 1, FullName = "Tigger", Species = Species.Tiger }; - var response = new AgentResponse(new ChatMessage(ChatRole.Assistant, JsonSerializer.Serialize(expectedResult, TestJsonSerializerContext.Default.Animal))); - - // Act. - var animal = response.Deserialize(); - - // Assert. - Assert.NotNull(animal); - Assert.Equal(expectedResult.Id, animal.Id); - Assert.Equal(expectedResult.FullName, animal.FullName); - Assert.Equal(expectedResult.Species, animal.Species); - } -#endif - [Fact] public void ParseAsStructuredOutputWithJSOSuccess() { @@ -246,7 +222,7 @@ public void ParseAsStructuredOutputWithJSOSuccess() var response = new AgentResponse(new ChatMessage(ChatRole.Assistant, JsonSerializer.Serialize(expectedResult, TestJsonSerializerContext.Default.Animal))); // Act. - var animal = response.Deserialize(TestJsonSerializerContext.Default.Options); + var animal = JsonSerializer.Deserialize(response.Text, TestJsonSerializerContext.Default.Options); // Assert. Assert.NotNull(animal); @@ -254,96 +230,4 @@ public void ParseAsStructuredOutputWithJSOSuccess() Assert.Equal(expectedResult.FullName, animal.FullName); Assert.Equal(expectedResult.Species, animal.Species); } - - [Fact] - public void ParseAsStructuredOutputFailsWithEmptyString() - { - // Arrange. - var response = new AgentResponse(new ChatMessage(ChatRole.Assistant, string.Empty)); - - // Act & Assert. - var exception = Assert.Throws(() => response.Deserialize(TestJsonSerializerContext.Default.Options)); - Assert.Equal("The response did not contain JSON to be deserialized.", exception.Message); - } - - [Fact] - public void ParseAsStructuredOutputFailsWithInvalidJson() - { - // Arrange. - var response = new AgentResponse(new ChatMessage(ChatRole.Assistant, "invalid json")); - - // Act & Assert. - Assert.Throws(() => response.Deserialize(TestJsonSerializerContext.Default.Options)); - } - - [Fact] - public void ParseAsStructuredOutputFailsWithIncorrectTypedJson() - { - // Arrange. - var response = new AgentResponse(new ChatMessage(ChatRole.Assistant, "[]")); - - // Act & Assert. - Assert.Throws(() => response.Deserialize(TestJsonSerializerContext.Default.Options)); - } - -#if NETFRAMEWORK - /// - /// Since Json Serialization using reflection is disabled in .net core builds, and we are using a custom type here that wouldn't - /// be registered with the default source generated serializer, this test will only pass in .net framework builds where reflection-based - /// serialization is available. - /// - [Fact] - public void TryParseAsStructuredOutputSuccess() - { - // Arrange. - var expectedResult = new Animal { Id = 1, FullName = "Tigger", Species = Species.Tiger }; - var response = new AgentResponse(new ChatMessage(ChatRole.Assistant, JsonSerializer.Serialize(expectedResult, TestJsonSerializerContext.Default.Animal))); - - // Act. - response.TryDeserialize(out Animal? animal); - - // Assert. - Assert.NotNull(animal); - Assert.Equal(expectedResult.Id, animal.Id); - Assert.Equal(expectedResult.FullName, animal.FullName); - Assert.Equal(expectedResult.Species, animal.Species); - } -#endif - - [Fact] - public void TryParseAsStructuredOutputWithJSOSuccess() - { - // Arrange. - var expectedResult = new Animal { Id = 1, FullName = "Tigger", Species = Species.Tiger }; - var response = new AgentResponse(new ChatMessage(ChatRole.Assistant, JsonSerializer.Serialize(expectedResult, TestJsonSerializerContext.Default.Animal))); - - // Act. - response.TryDeserialize(TestJsonSerializerContext.Default.Options, out Animal? animal); - - // Assert. - Assert.NotNull(animal); - Assert.Equal(expectedResult.Id, animal.Id); - Assert.Equal(expectedResult.FullName, animal.FullName); - Assert.Equal(expectedResult.Species, animal.Species); - } - - [Fact] - public void TryParseAsStructuredOutputFailsWithEmptyText() - { - // Arrange. - var response = new AgentResponse(new ChatMessage(ChatRole.Assistant, string.Empty)); - - // Act & Assert. - Assert.False(response.TryDeserialize(TestJsonSerializerContext.Default.Options, out _)); - } - - [Fact] - public void TryParseAsStructuredOutputFailsWithIncorrectTypedJson() - { - // Arrange. - var response = new AgentResponse(new ChatMessage(ChatRole.Assistant, "[]")); - - // Act & Assert. - Assert.False(response.TryDeserialize(TestJsonSerializerContext.Default.Options, out _)); - } } From dd169db0d1ee291b7f69c32320c7ec374ef4dd4a Mon Sep 17 00:00:00 2001 From: SergeyMenshykh Date: Fri, 30 Jan 2026 12:04:18 +0000 Subject: [PATCH 2/7] order usings --- dotnet/src/Microsoft.Agents.AI.Abstractions/AgentResponse.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/dotnet/src/Microsoft.Agents.AI.Abstractions/AgentResponse.cs b/dotnet/src/Microsoft.Agents.AI.Abstractions/AgentResponse.cs index e9cda50ad1..d79dbee135 100644 --- a/dotnet/src/Microsoft.Agents.AI.Abstractions/AgentResponse.cs +++ b/dotnet/src/Microsoft.Agents.AI.Abstractions/AgentResponse.cs @@ -4,10 +4,9 @@ using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; - using System.Text.Json.Serialization; -using Microsoft.Shared.Diagnostics; using Microsoft.Extensions.AI; +using Microsoft.Shared.Diagnostics; namespace Microsoft.Agents.AI; From c9da71cf68d24dcdee6fd5f96ef7826beff08dcf Mon Sep 17 00:00:00 2001 From: SergeyMenshykh <68852919+SergeyMenshykh@users.noreply.github.com> Date: Fri, 30 Jan 2026 12:06:43 +0000 Subject: [PATCH 3/7] Update dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step05_StructuredOutput/Program.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../FoundryAgents_Step05_StructuredOutput/Program.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step05_StructuredOutput/Program.cs b/dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step05_StructuredOutput/Program.cs index 0b67105ed1..3d70af0f93 100644 --- a/dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step05_StructuredOutput/Program.cs +++ b/dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step05_StructuredOutput/Program.cs @@ -61,7 +61,8 @@ // Assemble all the parts of the streamed output, since we can only deserialize once we have the full json, // then deserialize the response into the PersonInfo class. -PersonInfo personInfo = JsonSerializer.Deserialize((await updates.ToAgentResponseAsync()).Text, JsonSerializerOptions.Web)!; +PersonInfo personInfo = JsonSerializer.Deserialize((await updates.ToAgentResponseAsync()).Text, JsonSerializerOptions.Web) + ?? throw new InvalidOperationException("Failed to deserialize the streamed response into PersonInfo."); Console.WriteLine("Assistant Output:"); Console.WriteLine($"Name: {personInfo.Name}"); From f47ee9127d229600ea163f4dd98fe26ccf9a2c0b Mon Sep 17 00:00:00 2001 From: SergeyMenshykh <68852919+SergeyMenshykh@users.noreply.github.com> Date: Fri, 30 Jan 2026 12:06:54 +0000 Subject: [PATCH 4/7] Update dotnet/samples/GettingStarted/Workflows/_Foundational/08_WriterCriticWorkflow/Program.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../Workflows/_Foundational/08_WriterCriticWorkflow/Program.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dotnet/samples/GettingStarted/Workflows/_Foundational/08_WriterCriticWorkflow/Program.cs b/dotnet/samples/GettingStarted/Workflows/_Foundational/08_WriterCriticWorkflow/Program.cs index ebe3e24d41..9777e48705 100644 --- a/dotnet/samples/GettingStarted/Workflows/_Foundational/08_WriterCriticWorkflow/Program.cs +++ b/dotnet/samples/GettingStarted/Workflows/_Foundational/08_WriterCriticWorkflow/Program.cs @@ -327,7 +327,8 @@ public override async ValueTask HandleAsync( // Convert the stream to a response and deserialize the structured output AgentResponse response = await updates.ToAgentResponseAsync(cancellationToken); - CriticDecision decision = JsonSerializer.Deserialize(response.Text, JsonSerializerOptions.Web)!; + CriticDecision decision = JsonSerializer.Deserialize(response.Text, JsonSerializerOptions.Web) + ?? throw new JsonException("Failed to deserialize CriticDecision from response text."); Console.WriteLine($"Decision: {(decision.Approved ? "✅ APPROVED" : "❌ NEEDS REVISION")}"); if (!string.IsNullOrEmpty(decision.Feedback)) From a90d338229aa927ea0f0d38d42b7e8c7bdc5dceb Mon Sep 17 00:00:00 2001 From: SergeyMenshykh <68852919+SergeyMenshykh@users.noreply.github.com> Date: Fri, 30 Jan 2026 12:08:27 +0000 Subject: [PATCH 5/7] Update dotnet/samples/GettingStarted/AGUI/Step05_StateManagement/Server/SharedStateAgent.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../Step05_StateManagement/Server/SharedStateAgent.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/dotnet/samples/GettingStarted/AGUI/Step05_StateManagement/Server/SharedStateAgent.cs b/dotnet/samples/GettingStarted/AGUI/Step05_StateManagement/Server/SharedStateAgent.cs index 015e945f75..17bde7d215 100644 --- a/dotnet/samples/GettingStarted/AGUI/Step05_StateManagement/Server/SharedStateAgent.cs +++ b/dotnet/samples/GettingStarted/AGUI/Step05_StateManagement/Server/SharedStateAgent.cs @@ -139,7 +139,14 @@ private static bool TryDeserialize(string json, JsonSerializerOptions jsonSer { try { - structuredOutput = JsonSerializer.Deserialize(json, jsonSerializerOptions)!; + T? deserialized = JsonSerializer.Deserialize(json, jsonSerializerOptions); + if (deserialized is null) + { + structuredOutput = default!; + return false; + } + + structuredOutput = deserialized; return true; } catch From b72cd6fbfb6f5ea0f6b06b86efeb148b86957e49 Mon Sep 17 00:00:00 2001 From: SergeyMenshykh <68852919+SergeyMenshykh@users.noreply.github.com> Date: Fri, 30 Jan 2026 12:09:16 +0000 Subject: [PATCH 6/7] Update dotnet/samples/AGUIClientServer/AGUIDojoServer/SharedState/SharedStateAgent.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../AGUIDojoServer/SharedState/SharedStateAgent.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/dotnet/samples/AGUIClientServer/AGUIDojoServer/SharedState/SharedStateAgent.cs b/dotnet/samples/AGUIClientServer/AGUIDojoServer/SharedState/SharedStateAgent.cs index 96362a89a8..af1a54b103 100644 --- a/dotnet/samples/AGUIClientServer/AGUIDojoServer/SharedState/SharedStateAgent.cs +++ b/dotnet/samples/AGUIClientServer/AGUIDojoServer/SharedState/SharedStateAgent.cs @@ -108,7 +108,14 @@ private static bool TryDeserialize(string json, JsonSerializerOptions jsonSer { try { - structuredOutput = JsonSerializer.Deserialize(json, jsonSerializerOptions)!; + T? result = JsonSerializer.Deserialize(json, jsonSerializerOptions); + if (result is null) + { + structuredOutput = default!; + return false; + } + + structuredOutput = result; return true; } catch From 2924a8e02947c15112ff9cca211f14c70c075e3f Mon Sep 17 00:00:00 2001 From: SergeyMenshykh <68852919+SergeyMenshykh@users.noreply.github.com> Date: Fri, 30 Jan 2026 12:17:25 +0000 Subject: [PATCH 7/7] Update dotnet/samples/M365Agent/Agents/WeatherForecastAgent.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- dotnet/samples/M365Agent/Agents/WeatherForecastAgent.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/dotnet/samples/M365Agent/Agents/WeatherForecastAgent.cs b/dotnet/samples/M365Agent/Agents/WeatherForecastAgent.cs index e10c5b65c1..11caea6939 100644 --- a/dotnet/samples/M365Agent/Agents/WeatherForecastAgent.cs +++ b/dotnet/samples/M365Agent/Agents/WeatherForecastAgent.cs @@ -117,7 +117,14 @@ private static bool TryDeserialize(string json, JsonSerializerOptions jsonSer { try { - structuredOutput = JsonSerializer.Deserialize(json, jsonSerializerOptions)!; + T? result = JsonSerializer.Deserialize(json, jsonSerializerOptions); + if (result is null) + { + structuredOutput = default!; + return false; + } + + structuredOutput = result; return true; } catch