Skip to content

Debugger report null for uninited static struct field in classes without an .cctor #39993

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

Closed
yyjdelete opened this issue Jul 28, 2020 · 3 comments

Comments

@yyjdelete
Copy link

yyjdelete commented Jul 28, 2020

Description

Debugger will report null instead of default(...) for uninited static field(struct) in classes without an static ctor. It's an value type and should never be null.
Get null when watch the field in debugger, and ArgumentNullException when try to access any member of the field in debugger.

It only affect the debugger, running the program can get the right result. And after access the field in program or add an static ctor, the debugger can also get the right value.

Configuration

Which version of .NET is the code running on: netcoreapp2.1/3.1/net5.0(x64)
What OS and version, and what distro if applicable: win10 x64(2004)
What is the architecture (x64, x86, ARM, ARM64): x64
Debugger: VS/VSCode

Regression?

This seems happen on all version of netcore(not tested with 1.x), but not happen on any version of netframework(tested with net48), not sure if it's an issue of runtime or debugger of VS.

Other information

See null for Program.dateTime in debugger before Console.WriteLine and 0001-01-01 after Console.WriteLine

using System;
using System.Diagnostics;

namespace ConsoleApp7
{
    class Program
    {
        public static DateTime dateTime;

        static void Main(string[] args)
        {
            Debugger.Break();
            Console.WriteLine(Program.dateTime);
        }
    }
}
@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added area-Diagnostics-coreclr untriaged New issue has not been triaged by the area owner labels Jul 28, 2020
@ghost
Copy link

ghost commented Jul 28, 2020

Tagging subscribers to this area: @tommcdon
See info in area-owners.md if you want to be subscribed.

@tommcdon tommcdon added this to the 6.0.0 milestone Jul 28, 2020
@tommcdon tommcdon removed the untriaged New issue has not been triaged by the area owner label Jul 28, 2020
@tommcdon tommcdon modified the milestones: 6.0.0, Future Oct 13, 2020
Copy link
Contributor

Due to lack of recent activity, this issue has been marked as a candidate for backlog cleanup. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will undo this process.

This process is part of our issue cleanup automation.

@dotnet-policy-service dotnet-policy-service bot added backlog-cleanup-candidate An inactive issue that has been marked for automated closure. no-recent-activity labels Apr 14, 2025
Copy link
Contributor

This issue will now be closed since it had been marked no-recent-activity but received no further activity in the past 14 days. It is still possible to reopen or comment on the issue, but please note that the issue will be locked if it remains inactive for another 30 days.

@dotnet-policy-service dotnet-policy-service bot removed this from the Future milestone Apr 29, 2025
@github-actions github-actions bot locked and limited conversation to collaborators May 29, 2025
@dotnet-policy-service dotnet-policy-service bot removed no-recent-activity backlog-cleanup-candidate An inactive issue that has been marked for automated closure. labels May 29, 2025
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

3 participants