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
- Create a new .NET 6 console application using a template.
- Open csproj
- Add:
<PublishSingleFile>true</PublishSingleFile>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
- In the top of the application add:
while (!Debugger.IsAttached)
{
// Worked at first but suddenly stopped working?
Thread.Sleep(100);
}
Console.WriteLine("Attached.");
- Start generated executable
- 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
Description
I use
attach debugger to processon 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 forDebugger.IsAttachedto 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 thecsprojfile the debugger won't attach. In my case I need theRuntimeIdentifierto be set because I usePublishSingleFile.Reproduction Steps
while (!Debugger.IsAttached)
{
// Worked at first but suddenly stopped working?
Thread.Sleep(100);
}
Console.WriteLine("Attached.");
Expected behavior
Attaching debugger should trigger the
Debugger.IsAttachedstatement 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 5and recompile. Debugger will now attach successfully.Known Workarounds
In my case I worked around the issue by settings the
RuntimeIdentifieronly on release. Release is the configuration the publish command will be used with anyway: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