Skip to content

Type preinitialization skips dataflow analysis #97286

@MichalStrehovsky

Description

@MichalStrehovsky

There's an assignment to a DAM member but since we interpret the cctor instead of executing it, it bypasses the DAM annotations: this program will nullref at runtime.

This is a regression in 9.0.

using System;
using System.Diagnostics.CodeAnalysis;

Preinit.TheType.GetMethod("TheMethod").Invoke(null, []);

class Preinit
{
    [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)]
    public static Type TheType = typeof(Preinit);

    public static void TheMethod() => Console.WriteLine("Hello");
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    No status

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions