Skip to content

.NET Debugging services don't issue thread create callbacks for single file apps #77574

@gregg-miskelly

Description

@gregg-miskelly

Description

When debugging a .NET 7 application published in single-file mode, the .NET debugging services don't issue ICorDebugManagedCallback.CreateThread call backs, causing the threads window in Visual Studio to be missing threads.

For what it is worth, this didn't reproduce in .NET 6.

Reproduction Steps

  1. Create a new .NET 7 console application with the following code
  2. dotnet publish it
  3. Open the single file executable as an exe project in Visual Studio or another managed debugger
  4. Launch
  5. When the Debugger.Break() is hit, open the threads window or the parallel stacks window

Program.cs:

using System.Diagnostics;

void KickOffThreadPoolThread(ManualResetEvent manualResetEvent)
{
    Task.Run(() =>
    {
        manualResetEvent.Set();
        while (true)
        {
            Thread.Sleep(100);
        }
    });
}

var manualResetEvents = new ManualResetEvent[10];
for (int i = 0; i < manualResetEvents.Length; i++)
{
    manualResetEvents[i] = new ManualResetEvent(false);
    KickOffThreadPoolThread(manualResetEvents[i]);
}

ManualResetEvent.WaitAll(manualResetEvents);
Debugger.Break();

Project file:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net7.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>

    <!--Enable single file-->
    <PublishSingleFile>true</PublishSingleFile>
    <RuntimeIdentifier>win7-x64</RuntimeIdentifier>
    <SelfContained>true</SelfContained>
  </PropertyGroup>
</Project>

Expected behavior

.NET Debugging services will issue ICorDebugManagedCallback.CreateThread call backs, so the parallel stacks window will have all the threads

Actual behavior

No CreateThread callback is triggered for the thread pool threads, so the parallel stacks window will only show the main thread:
image

Regression?

This same scenario works in .NET 6.

Known Workarounds

Debugger can call EnumerateThreads

Configuration

Version: .NET 7 RC2
OS: Windows
Architecture: x64

I didn't try other configurations other than .NET 6

Other information

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions