Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Specify DateTimeKind.Utc in JSON tests to avoid ArgumentOutOfRangeException - #39547

Merged
layomia merged 1 commit into
dotnet:masterfrom
bjorkstromm:fix-json-tests-datetime-utc
Jul 16, 2019
Merged

layomia merged 1 commit into
dotnet:masterfrom
bjorkstromm:fix-json-tests-datetime-utc

Conversation

@bjorkstromm

Copy link
Copy Markdown
Member

Found this issue when testing #39541 which fixes #39067

I saw that there was an implicit cast from DateTime to DateTimeOffset (without specifying DateTimeKind) in System.Text.Json.Serialization.Tests.StreamTests.LargeJsonFile tests. Specifying the DateTimeKind to UTC makes the tests pass.

Original exception before fix:

System.ArgumentOutOfRangeException : The UTC time represented when the offset is applied must be between year 0 and 10,000. (Parameter 'offset')]]
   at System.DateTimeOffset.ValidateDate(DateTime dateTime, TimeSpan offset) in /_/src/System.Private.CoreLib/shared/System/DateTimeOffset.cs:line 967
   at System.DateTimeOffset..ctor(DateTime dateTime) in /_/src/System.Private.CoreLib/shared/System/DateTimeOffset.cs:line 81
   at System.DateTimeOffset.op_Implicit(DateTime dateTime) in /_/src/System.Private.CoreLib/shared/System/DateTimeOffset.cs:line 998
   at System.Text.Json.Serialization.Tests.StreamTests.LargeJsonFile(Int32 bufferSize) in C:\Users\mb\src\gh\corefx\src\System.Text.Json\tests\Serialization\Stream.WriteTests.cs:line 200
--- End of stack trace from previous location where exception was thrown

//cc @layomia

@layomia
layomia requested a review from steveharter July 16, 2019 19:44
@layomia layomia added this to the 3.0 milestone Jul 16, 2019
@layomia
layomia self-requested a review July 16, 2019 19:50

@layomia layomia 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.

Thanks!

@layomia
layomia merged commit 6cd505d into dotnet:master Jul 16, 2019
@bjorkstromm
bjorkstromm deleted the fix-json-tests-datetime-utc branch July 17, 2019 07:29
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

System.Text.Json Deserialization - Can't parse DateTime.MinValue if UTC offset is greater than 0

2 participants