Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DateTime? proprety value cannot be set correctly #7562

Closed
tarekgh opened this issue Mar 5, 2017 · 2 comments
Closed

DateTime? proprety value cannot be set correctly #7562

tarekgh opened this issue Mar 5, 2017 · 2 comments

Comments

@tarekgh
Copy link
Member

tarekgh commented Mar 5, 2017

@tongqijie commented on Fri Mar 03 2017

i have a class contains a property whose type is DateTime?

public class SubItem
{
    public string StringValue { get; set; }

    public int? IntegerValue { get; set; }

    public DateTime? DateValue { get; set; }

    public bool? BooleanValue { get; set; }
}

i set value to property 'DateValue' like this:

var subItem = new SubItem();
subItem.DateValue = DateTime.Now;

the problem is that subItem.DateValue is always {01/01/0001 00:07:28}. why?

please help me...


@tongqijie commented on Fri Mar 03 2017

here is my dotnet --info:

.NET Command Line Tools (1.0.0-preview2-003131)

Product Information:
 Version:            1.0.0-preview2-003131
 Commit SHA-1 hash:  635cf40e58

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  10.12
 OS Platform: Darwin
 RID:         osx.10.12-x64

@tongqijie commented on Fri Mar 03 2017

it works fine on windows.

.NET Command Line Tools (1.0.0-preview2-003131)

Product Information:
 Version:            1.0.0-preview2-003131
 Commit SHA-1 hash:  635cf40e58

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.14393
 OS Platform: Windows
 RID:         win10-x64

@svick commented on Sat Mar 04 2017

The following code works fine for me on Linux:

using System;

public class SubItem
{
    public string StringValue { get; set; }

    public int? IntegerValue { get; set; }

    public DateTime? DateValue { get; set; }

    public bool? BooleanValue { get; set; }
}

public class Program
{
    public static void Main()
    {
        var subItem = new SubItem();
        subItem.DateValue = DateTime.Now;
        Console.WriteLine(subItem.DateValue);
    }
}

Could you share a complete program that demonstrates the issue? How exactly are you viewing the value? Are you using some debugger or IDE? Are you sure your machine has the correct time set?


@tongqijie commented on Sat Mar 04 2017

public class Program
{
    public static void Main(string[] args)
    {
        var subItem = new SubItem();
        subItem.DateValue = DateTime.Now;

        Console.WriteLine(subItem.DateValue?.ToString());
    }

    public class SubItem
    {
        public string StringValue { get; set; }

        public int? IntegerValue { get; set; }

        public DateTime? DateValue { get; set; }

        public bool? BooleanValue { get; set; }
    }
}

today, i found it worked fines, but it was weird to watch variable's value when debugging.

201703050001


@svick commented on Sat Mar 04 2017

I can see the same behavior in VS Code on Linux.

I believe this is dotnet/vscode-csharp#753, which is in turn caused by https://github.com/dotnet/coreclr/issues/7115, which should be fixed in the next version of .Net Core. But it is only a debugging bug, so it shouldn't affect how your application actually executes.

@gkhanna79
Copy link
Member

@lt72 @mikem8361 PTAL and close (with details) if already fixed.

@mikem8361
Copy link
Member

PR dotnet/coreclr#7149 in coreclr fixed this and it should have made it into .NET Core 1.1.

@msftgits msftgits transferred this issue from dotnet/coreclr Jan 31, 2020
@msftgits msftgits added this to the 2.0.0 milestone Jan 31, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants