Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.net core 3.1 to .net Core 5 upgrade gives wrong conversion for datetime values? Any document for this breaking changes and solution

Recently upgrade one application from .NET Core 3.1 to .NET 5. For some reason the DateTimeKind was Local in 3.1 and now it is UTC in .NET 5.

I created a simple project showing this problem,

https://github.com/ShehulCS/Dotnet5DateTimeIssue

Question,

  1. Can anyone please confirm from Microsoft docs, if this was the change they introduce between 2 versions, is it a bug or new design? Online search doesn't lead me to anything useful on this.
like image 849
user3900019 Avatar asked Sep 11 '25 16:09

user3900019


1 Answers

The issue you're describing is related to a bug fix.

In short, the Z at the end of an ISO 8601 timestamp explicitly means UTC. The bug was that when such a value is obtained through model binding, it was previously being interpreted as DateTimeKind.Local instead of DateTimeKind.Utc. That bug has been corrected in 5.0.

  • The bug is described in this issue: https://github.com/dotnet/aspnetcore/issues/11584

  • It was fixed in this PR: https://github.com/dotnet/aspnetcore/pull/24893

  • A request to backport the fix to 3.1 was made (but denied) here: https://github.com/dotnet/aspnetcore/issues/27618

The new behavior is correct. If you were relying on the old behavior, you probably have other .NET code that needs to be corrected.

like image 194
Matt Johnson-Pint Avatar answered Sep 14 '25 07:09

Matt Johnson-Pint