You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
System.Xml.XmlConvert.ToDateTimeOffset("0001-01-01T00:00:00") throws ArgumentOutOfRangeException for timezones with positive offset #130814
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:
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:
caseXsdDateTimeKind.Unspecified:default:
result =newDateTimeOffset(dt,TimeZoneInfo.Local.GetUtcOffset(dt));break;
It should be replaced with:
case XsdDateTimeKind.Unspecified:default:if(dt==DateTime.MinValue){result=DateTimeOffset.MinValue;}else{result=newDateTimeOffset(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
dotnet-policy-service commentedon Jul 15, 2026
Tagging subscribers to this area: @dotnet/area-system-datetime
See info in area-owners.md if you want to be subscribed.
dotnet-policy-service commentedon Jul 15, 2026
Tagging subscribers to this area: @dotnet/area-system-xml
See info in area-owners.md if you want to be subscribed.
Handle XmlConvert unspecified DateTimeOffset at local time-zone bound…