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

Process silently exits after patching self-contained app with Debug bits when specific breakpoints are set #106104

Open mikelle-rogers opened 2 months ago

mikelle-rogers commented 2 months ago

Description

The process that I am running on .NET9 preview 7 under the debugger silently exits either after stepping, or it continuing and breakpoints are set on the lines after var aa = typeof(Action).GetMethod("Invoke").CreateDelegate<Action<Action>>();

Reproduction Steps

class Program 
{ 
    static int x; 
    static void Main() 
    { 
        Action a = Work; 
        a += Work2; 
        a += Work3; 
        var aa = typeof(Action).GetMethod("Invoke").CreateDelegate<Action<Action>>();

        //for (; ; ) a(); 
        Console.WriteLine("We are here");
        for (; ; ) aa(a); 
    } 
    static void Work() 
    { 
        Console.WriteLine("work");
        x += 1; 
    } 
    static void Work2() 
    { 
        Console.WriteLine("work2");
        x += 2; 
    } 
    static void Work3() 
    { 
        Console.WriteLine("work3");
        x += 3; 
    } 
}

Publish this as self-contained, then build the runtime in Debug and patch the Runtime. Put breakpoints on the Console.WriteLine("We are here"); line or the for loop line.

Expected behavior

The program continues and the Console.WriteLine lines print.

Actual behavior

If breakpoints are on either of the lines after var aa = typeof(Action).GetMethod("Invoke").CreateDelegate<Action<Action>>();, then the program and the debugger silently fail and exit.

Regression?

No response

Known Workarounds

Don't set breakpoints and run the program, then it works as expected. Or just use the self-contained runtime after publishing the app rather than patching a Debug runtime.

Configuration

Mac ARM64 -> M1 .NET9, patched Debug build

Other information

No response

dotnet-policy-service[bot] commented 2 months ago

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