Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix ReadContentAsDateTime method to keep DateTimeKind #114969

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

BradBarnich
Copy link

potential fix for #114813

roundtripping through DateTimeOffset.DateTime loses the DateTimeKind, which in some code paths causes incorrect interpretation in DateTimeOffsetAdapter

this is also what the code looks like in framework: https://github.com/microsoft/referencesource/blob/master/System.Runtime.Serialization/System/Runtime/Serialization/XmlSerializableReader.cs#L117

@Copilot Copilot AI review requested due to automatic review settings April 23, 2025 19:25
Copy link
Contributor

@Copilot Copilot AI left a comment

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 addresses issue #114813 by updating the ReadContentAsDateTime method to preserve the DateTimeKind, aligning its behavior with the framework's implementation.

  • Updated ReadContentAsDateTime to directly call InnerReader.ReadContentAsDateTime() instead of extracting the DateTime from a DateTimeOffset.
  • Ensured consistency with the framework's implementation as referenced in the description.

@@ -115,7 +115,7 @@ public override void Close()

public override object ReadContentAsObject() { return InnerReader.ReadContentAsObject(); }
public override bool ReadContentAsBoolean() { return InnerReader.ReadContentAsBoolean(); }
public override DateTime ReadContentAsDateTime() { return InnerReader.ReadContentAsDateTimeOffset().DateTime; }
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to create a regression test for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Serialization community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants