diff --git a/dotnet/samples/AgentWebChat/AgentWebChat.Web/AgentDiscoveryClient.cs b/dotnet/samples/AgentWebChat/AgentWebChat.Web/AgentDiscoveryClient.cs index 09e3c9d630..7351ba6625 100644 --- a/dotnet/samples/AgentWebChat/AgentWebChat.Web/AgentDiscoveryClient.cs +++ b/dotnet/samples/AgentWebChat/AgentWebChat.Web/AgentDiscoveryClient.cs @@ -1,7 +1,6 @@ // Copyright (c) Microsoft. All rights reserved. using System.Text.Json; -using Microsoft.Agents.AI.Hosting; namespace AgentWebChat.Web; @@ -13,7 +12,7 @@ public class AgentDiscoveryClient(HttpClient httpClient, ILogger>(json, AgentHostingJsonUtilities.DefaultOptions) ?? []; + var agents = JsonSerializer.Deserialize>(json) ?? []; logger.LogInformation("Retrieved {AgentCount} agents from the API", agents.Count); return agents; diff --git a/dotnet/src/Microsoft.Agents.AI.Hosting/AgentHostingJsonUtilities.cs b/dotnet/src/Microsoft.Agents.AI.Hosting/AgentHostingJsonUtilities.cs deleted file mode 100644 index 95a930a9a2..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Hosting/AgentHostingJsonUtilities.cs +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using System.Diagnostics.CodeAnalysis; -using System.Text.Json; -using System.Text.Json.Serialization; - -namespace Microsoft.Agents.AI.Hosting; - -/// Provides a collection of utility methods for working with JSON data in the context of agent hosting. -public static partial class AgentHostingJsonUtilities -{ - /// - /// Gets the singleton used as the default in JSON serialization operations. - /// - /// - /// - /// For Native AOT or applications disabling , this instance - /// includes source generated contracts for all common exchange types contained in this library. - /// - /// - /// It additionally turns on the following settings: - /// - /// Enables defaults. - /// Enables as the default ignore condition for properties. - /// Enables as the default number handling for number types. - /// - /// - /// - public static JsonSerializerOptions DefaultOptions { get; } = CreateDefaultOptions(); - - /// - /// Creates default options to use for agent hosting-related serialization. - /// - /// The configured options. - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL3050:RequiresDynamicCode", Justification = "Converter is guarded by IsReflectionEnabledByDefault check.")] - [UnconditionalSuppressMessage("Trimming", "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access", Justification = "Converter is guarded by IsReflectionEnabledByDefault check.")] - private static JsonSerializerOptions CreateDefaultOptions() - { - // Copy the configuration from the source generated context. - JsonSerializerOptions options = new(JsonContext.Default.Options); - - // Chain with all supported types from Microsoft.Agents.AI.Abstractions. - options.TypeInfoResolverChain.Add(AgentAbstractionsJsonUtilities.DefaultOptions.TypeInfoResolver!); - - options.MakeReadOnly(); - return options; - } - - // Keep in sync with CreateDefaultOptions above. - [JsonSourceGenerationOptions(JsonSerializerDefaults.Web, - DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, - NumberHandling = JsonNumberHandling.AllowReadingFromString)] - [JsonSerializable(typeof(AgentThread))] - [ExcludeFromCodeCoverage] - internal sealed partial class JsonContext : JsonSerializerContext; -} diff --git a/dotnet/src/Microsoft.Agents.AI/AgentJsonUtilities.cs b/dotnet/src/Microsoft.Agents.AI/AgentJsonUtilities.cs index 439bf2852c..38ce925d5a 100644 --- a/dotnet/src/Microsoft.Agents.AI/AgentJsonUtilities.cs +++ b/dotnet/src/Microsoft.Agents.AI/AgentJsonUtilities.cs @@ -7,7 +7,7 @@ using System.Text.Json.Serialization; namespace Microsoft.Agents.AI; /// Provides a collection of utility methods for working with JSON data in the context of agents. -public static partial class AgentJsonUtilities +internal static partial class AgentJsonUtilities { /// /// Gets the singleton used as the default in JSON serialization operations.