Search code examples
c#visual-studiodebugging.net-4.0

Debugger.Launch not working


I am currently trying to launch a debugger for a process that is launched externally (not from within visual studio). I cannot seem to get a debugger actually launch, as it appears nothing happens. In the process, I added this code:

Debug.Assert(Debugger.IsAttached == false, "Should be no debugger");
if (!Debugger.IsAttached)
{
    Debug.Assert(Debugger.Launch(), "Debugger not launched");
}
Debugger.Break();
Debug.Assert(Debugger.IsAttached == true, "Debugger should be attached");

The asserts are there to verify that I'm not crazy. At first, the IsAttached property returns false as I expect. I then call Debugger.Launch, and that returns true. As per the MSDN documentation of Debugger.Launch, it says it will only return true if it succeeds in launching the debugger, or if one is already attached. I verified one was not attached, so it must have launched one.

The break-point never gets hit, and the second verify fails (the IsAttached property returns false). I also attempted to put a sleep in after Debugger.Launch to give it some time, to no avail.

Any suggestions?


Solution

  • I have the same problem in Visual Studio 2013 Premium. Eric's answer put me over how to resolve it. But you don't need to change the register.

    1. Go to Tools --> Options --> Debugging
    2. Open the item and select just in time debugger
    3. If you see in the low part of the window a yellow warning about that other debug is being used different to Visual Studio. If you see that, check all Just in Time checkboxes to return to VS to be the debug program.

    That is all!

    Options Just in Time debugger