Skip to content

Unable to attach debugger to process using .NET 6 when Runtimeidentifier is set to x64 #67327

@Pettor

Description

@Pettor

Description

I use attach debugger to process on a .NET 5 compiled console application successfully. After upgrading the project to .NET 6 this stopped working. At the top of the application I wait for Debugger.IsAttached to return true before continuing execution of the application. To find the specific problem I created a new .NET 6 application from a template and was able to attach the debugger.

I started backtracking what the root cause was for the debugger failure and found that whenver I set <RuntimeIdentifier>win-x64</RuntimeIdentifier> in the csproj file the debugger won't attach. In my case I need the RuntimeIdentifier to be set because I use PublishSingleFile.

Reproduction Steps

  1. Create a new .NET 6 console application using a template.
  2. Open csproj
  3. Add:
<PublishSingleFile>true</PublishSingleFile>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
  1. In the top of the application add:
    while (!Debugger.IsAttached)
    {
    // Worked at first but suddenly stopped working?
    Thread.Sleep(100);
    }
    Console.WriteLine("Attached.");
  2. Start generated executable
  3. Attach debugger to running process

Expected behavior

Attaching debugger should trigger the Debugger.IsAttached statement in the compiled code.

Actual behavior

Application is stuck and unable to attach debugger to the process.

Regression?

Change the project type to use .NET 5 and recompile. Debugger will now attach successfully.

Known Workarounds

In my case I worked around the issue by settings the RuntimeIdentifier only on release. Release is the configuration the publish command will be used with anyway:

<PublishTrimmed Condition="'$(Configuration)' == 'Release'">true</PublishTrimmed>
<PublishReadyToRun Condition="'$(Configuration)' == 'Release'">true</PublishReadyToRun>
<PublishSingleFile Condition="'$(Configuration)' == 'Release'">true</PublishSingleFile>
<RuntimeIdentifier Condition="'$(Configuration)' == 'Release'">win-x64</RuntimeIdentifier>

Configuration

dotnet: 6.0.101
Visual Studio 2022: Version 17.0.5
Rider: 2021.3.3 Build #RD-213.6775.4, built on January 26, 2022
Windows 11: 22000.556

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions