none
Debugging a Windows Service (VS 2008 / .NET 3.5) Using Debugger.Launch()

    Question

  • Hi, Everybody!

    I wrote a Windows Service using VS 2008 (.NET 3.5).  I wish to debug it.  I am able to build it and install it successfully.  When I start the service, the Visual Studio Just-In-Time Debugger (VS JIT Debugger) appears displaying the following message: An unhandled exception ("Launch for user") occurred in <WindowsService> [3392] (or [2560] or [5180] or ...).  I select the following Possible Debuggers <WindowsService> - Microsoft Visual Studio: Visual Studio 2008 and click the Yes button.  This is followed immediately by the following dialog box: Caption: Microsoft Visual Studio, Message: There is no source code available for the current location.  Clicking the Show Disassembly button results in displaying the disassembly.  The call stack shows mscorlib.dll!System.Diagnostics.Debugger.Launch() + 0x6a bytes.  The exception apparently occurs in Debugger.Launch();.  If I choose to continue, I am able to debug the Windows Service, stopping at the specified break points.  Why does the VS JIT Debugger appear in the first place?  How can I use Debugger.Launch(); without the VS JIT Debugger appearing?  See code below...

      protected override void OnStart(string[] args)
      {
       try
       {
        Debugger.Launch();
        var t = new Thread(Start);
        t.IsBackground = true;
        t.Start();
       }
       catch (Exception ex)
       {
        using (var sw = new StreamWriter(<some log file>, true))
        {
         sw.WriteLine("Exception encountered in OnStart method...");
         sw.WriteLine("See Exception.ToString() below...");
         sw.WriteLine(ex.ToString());
        }
       }
      }
    
    Wednesday, September 08, 2010 8:42 AM

Answers