Skip to content

GetStaticFieldByName or enumerating static fields and reading their values return 0 on .NET 9 #1313

Open
@chendror

Description

@chendror

Executing the following code with a debuggee that runs with .NET 9 doesn't print anything:

using DataTarget target = DataTarget.AttachToProcess(pid, suspend: false);
ClrInfo clrInfo = target.ClrVersions.Single();
ClrRuntime runtime = clrInfo.CreateRuntime();
foreach (var module in runtime.EnumerateModules()) {
    foreach (var entry in module.EnumerateTypeDefToMethodTableMap()) {
        ClrType? type = runtime.GetTypeByMethodTable(entry.MethodTable);
        foreach (ClrStaticField? m in type?.StaticFields) {
            if (m.GetAddress(runtime.AppDomains.Single()) != 0) {
                Console.WriteLine($"{type} {m} {m.IsObjectReference} {m.IsInitialized(runtime.AppDomains.Single())} {m.GetAddress(runtime.AppDomains.Single())}");
            }
        }
    }
}

When I execute the same code with a debuggee that runs with .NET 8 or .NET 7 it prints many fields.
I tried it with a simple .NET project that I wrote, and also with different pwsh versions (worked for 7.4.5 and 7.3.0, but didn't work for 7.5.0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions