Skip to content

.NET: [Feature]: .NET Improve ChatClientAgentSession constructor#7142

Merged
rogerbarreto merged 3 commits into
microsoft:mainfrom
feiyun0112:issues/7109
Jul 16, 2026
Merged

.NET: [Feature]: .NET Improve ChatClientAgentSession constructor#7142
rogerbarreto merged 3 commits into
microsoft:mainfrom
feiyun0112:issues/7109

Conversation

@feiyun0112

Copy link
Copy Markdown
Contributor

fix #7109

Copilot AI review requested due to automatic review settings July 16, 2026 10:45
@giles17 giles17 added the .NET Usage: [Issues, PRs], Target: .Net label Jul 16, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adjusts .NET ChatClientAgentSession JSON deserialization behavior to work with stricter System.Text.Json settings (notably RespectRequiredConstructorParametersDefault=true) when optional properties are omitted due to JsonIgnoreCondition.WhenWritingNull.

Changes:

  • Makes the [JsonConstructor] constructor parameters optional by adding default values, preventing deserialization failures when JSON omits null properties.
  • Adds a unit test to validate round-trip behavior when serialization uses DefaultIgnoreCondition = WhenWritingNull.
  • Adds XML documentation for the JSON constructor parameters.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgentSession.cs Updates the [JsonConstructor] signature to accept omitted JSON properties via optional parameters and documents the constructor.
dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgentSessionTests.cs Adds a test covering WhenWritingNull serialization + subsequent deserialization using provided options.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
VerifyDeserializeWithWhenWritingNullOptions passed against both the old
and the fixed constructor, so it did not guard against the regression.

The bug only reproduces when required constructor parameters are respected
(the issue uses RespectRequiredConstructorParametersDefault=true). With
WhenWritingNull a null conversationId is omitted from the JSON, and STJ then
throws 'missing required properties including: conversationId' because the
constructor parameter had no default value.

Adding RespectRequiredConstructorParameters = true to the test options makes
the test red against the parameter-without-default constructor and green with
the default-valued constructor parameters, so it now protects the fix.
@rogerbarreto
rogerbarreto enabled auto-merge July 16, 2026 14:54
@rogerbarreto
rogerbarreto added this pull request to the merge queue Jul 16, 2026
Merged via the queue into microsoft:main with commit dde7635 Jul 16, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

.NET Usage: [Issues, PRs], Target: .Net

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.NET: [Feature]: .NET Improve ChatClientAgentSession constructor

5 participants