dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.26k stars 4.73k forks source link

[NativeAOT] `DiagnosticMethodInfo.Create(Delegate)` does not work with closed delegates over instance methods on value types #108688

Open SingleAccretion opened 4 weeks ago

SingleAccretion commented 4 weeks ago

Reproduction (compile, publish, run):

using System;
using System.Diagnostics;

class Program
{
    static void Main()
    {
        DelStruct s;
        ClosedDel del = s.InstanceMethod;
        var dmi = DiagnosticMethodInfo.Create(del);
        Console.WriteLine(dmi is null);
    }

    delegate void ClosedDel();

    struct DelStruct
    {
        public void InstanceMethod() { }
    }
}

Expected result:

False

Actual result:

True

The problem is that code here may pass an unboxing thunk address to the stack trace logic, which the latter doesn't understand - stack trace data records only unboxed entrypoints.

It probably makes sense to normalize the entrypoints on this path to their unboxed form (the reflection-based lookup will understand both).

dotnet-policy-service[bot] commented 4 weeks ago

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas See info in area-owners.md if you want to be subscribed.