Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# - How to continue after failing to attach debugger - System.Diagnostics.Debugger.Launch()

Tags:

c#

debugging

I attach a debugger by passing '-d' as a command line parameter to my console app. That causes the following code to be called;

bool attachedDebugger = false;
try
{
   attachedDebugger = System.Diagnostics.Debugger.Launch();
}
catch (Exception) { }
finally
{
   Console.WriteLine(attachedDebugger ? "Debugger Attached" : "Failed to attach debugger");
}

After the Visual Studio 2010 JIT window pops up I sometimes change my mind and don't want to debug, so I dismiss the dialog. If I don't attach one then the Application exits immediately without anything being written to the console.

I know that this it a bit of an edge use case, I should just remove the '-d' from the command line if I don't want to debug. The reason for my question is that I wish to understand what's happening.

I thought the finally block is always called, furthermore I would expect my application to continue if we fail to attach a debugger.

  • Why is nothing printed to the console if I decline attaching a debugger?
  • Does Debugger.Launch() call System.Exit on failure to attach?

EDIT Thanks @Moo-Juice I now know that a return value of false implies a debugger was already attached but the questions above remain unresolved.

like image 316
CityView Avatar asked Nov 06 '22 06:11

CityView


1 Answers

This is a reported bug in dotnet 4.0

like image 89
Kell Avatar answered Nov 12 '22 10:11

Kell