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.Text.Json fails to deserialize datetime #29964
publicclassMyRecord{publicintIDValue{get;set;}publicstringNameValue{get;set;}publicDateTimeDateTimeValue{get;set;}publicDecimalDecimalValue{get;set;}}...// create a record, fill-in only some propertiesMyRecord myRecord =newMyRecord{IDValue=1};// serialize to stringstringserializedValue=System.Text.Json.Serialization.JsonSerializer.ToString(myRecord);// deserializeMyRecorddeserializedRecord=System.Text.Json.Serialization.JsonSerializer.Parse<MyRecord>(serializedValue);
This produces an error:
System.Text.Json.JsonException
Message=The JSON value could not be converted to System.DateTime. Path: $.DateTimeValue | LineNumber: 0 | BytePositionInLine: 67.
Source=System.Text.Json
Is this a bug in System.Text.Json, or is there any recommendation how to handle "empty" datetimes?
Looks like you're on .NET Core 3.0 P5 or the NuGet pacakge before P6; have you tried it on P6? it seems to work fine on the latest...ish master branch.
(Note that JsonSerializer has been moved to System.Text.Json out of the Serialization namespace)
And this is from the compiler output:
C:\Program Files\dotnet\sdk\3.0.100-preview6-012264\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.RuntimeIdentifierInference.targets(158,5): message NETSDK1057: You are using a preview version of .NET Core.
Activity
Gnbrkm41 commentedon Jun 20, 2019
Looks like you're on .NET Core 3.0 P5 or the NuGet pacakge before P6; have you tried it on P6? it seems to work fine on the latest...ish master branch.
(Note that
JsonSerializerhas been moved toSystem.Text.Jsonout of theSerializationnamespace)radek7210 commentedon Jun 20, 2019
I'm on P6 (don't have P5 installed) -
λ dotnet --list-runtimes
Microsoft.AspNetCore.All 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.0.0-preview6.19307.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.0.0-preview6-27804-01 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.0.0-preview6-27804-01 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
λ dotnet --list-sdks
2.1.507 [C:\Program Files\dotnet\sdk]
2.1.700 [C:\Program Files\dotnet\sdk]
2.1.800-preview-009696 [C:\Program Files\dotnet\sdk]
2.2.300 [C:\Program Files\dotnet\sdk]
3.0.100-preview6-012264 [C:\Program Files\dotnet\sdk]
And this is from the compiler output:
C:\Program Files\dotnet\sdk\3.0.100-preview6-012264\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.RuntimeIdentifierInference.targets(158,5): message NETSDK1057: You are using a preview version of .NET Core.
Gnbrkm41 commentedon Jun 20, 2019
Hmm, maybe it's fixed post-P6 perhaps. (I'm on 3.0.100-preview7-012426) I'm able to deserialize the JSON string back and read the properties:
radek7210 commentedon Jun 20, 2019
ok then, I will wait for P7, no problem.
Thanks for your time.
Gnbrkm41 commentedon Jun 20, 2019
If you want to try it yourself, you could follow this:
https://github.com/dotnet/corefx/blob/master/Documentation/project-docs/dogfooding.md
layomia commentedon Jun 20, 2019
As @Gnbrkm41 pointed out, this issue is not reproducible in the current build, so I'm closing this for now.
@radek7210 , please feel free to re-open if you sync to the latest build and still get this issue - https://github.com/dotnet/core-sdk#installers-and-binaries.