Skip to content

System.Xml.XmlConvert.ToDateTimeOffset("0001-01-01T00:00:00") throws ArgumentOutOfRangeException for timezones with positive offset #130814

Closed

Description

@mconnew

Description

When using an XmlReader to read the string 0001-01-01T00:00:00 as a DateTime, it uses XmlConvert.ToDateTimeOffset, and then takes the DateTime component from it. This results in an ArgumentOutOfRangeException with the message "The UTC time represented when the offset is applied must be between year 0 and 10,000. (Parameter 'offset')". This is caused by the problem described in #47460 and is affecting CoreWCF/WCF users as mentioned in CoreWCF/CoreWCF#1747.

Reproduction Steps

On a host that's configured with a positive offset timezone, running the following code will throw ArgumentOutOfRangeException:

var dto = System.Xml.XmlConvert.ToDateTimeOffset("0001-01-01T00:00:00");

Expected behavior

To return a DateTimeOffset representing DateTimeOffset.MinValue.

Actual behavior

Throws ArgumentOutOfRangeException.

Regression?

Yes, this works on .NET Framework and .NET versions prior to the change described in issue #47460

Known Workarounds

None, as this is used deep inside XmlReader

Configuration

.NET 10, but will be failing on all currently supported .NET versions

Other information

In the implicit cast operator for System.Xml.Schema.XsdDateTime to convert it to DateTimeOffset, located at src/runtime/src/libraries/System.Private.Xml/src/System/Xml/Schema/XsdDateTime.cs, it has the following snippet of code:

                case XsdDateTimeKind.Unspecified:
                default:
                    result = new DateTimeOffset(dt, TimeZoneInfo.Local.GetUtcOffset(dt));
                    break;

It should be replaced with:

                case XsdDateTimeKind.Unspecified:
                default:
                    if (dt == DateTime.MinValue)
                    {
                        result = DateTimeOffset.MinValue;
                    }
                    else
                    {
                        result = new DateTimeOffset(dt, TimeZoneInfo.Local.GetUtcOffset(dt));
                    }
                    break;

We only need to worry about setting the offset if it isn't the min value. This still leaves a small range of values which will still be a problem. If you use a datetime value that's MinValue + 1 hour, and your TZ offset is greater than 1 hour, it will still have a problem. But in that case, it's a value we're still unable to represent so failure is the correct behavior. MinValue has a specific meaning outside of the point in time the value is referencing and DateTimeOffset.MinValue without specifying the offset is equivalent.

Activity

  1. added
    untriaged
    on Jul 15, 2026
  2. dotnet-policy-service commented on Jul 15, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @dotnet/area-system-datetime
    See info in area-owners.md if you want to be subscribed.

  3. dotnet-policy-service commented on Jul 15, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @dotnet/area-system-xml
    See info in area-owners.md if you want to be subscribed.

  4. removed
    untriaged
    on Jul 15, 2026
  5. added this to the 11.0.0 milestone on Jul 15, 2026
  6. added a commit that references this issue on Jul 16, 2026
    1594ad1
  7. locked and limited conversation to collaborators on Aug 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions