Attaching to a Running Process

Occasionally you will need to start debugging a process that is already running. This has happened to me with ASP.NET applications. Every once in a while some inexplicable internal calamity will occur and I won't be able to start an ASP.NET application in debug mode. Instead of rebooting, which usually resolves the problem, I can start the application without debugging. (Start without Debugging is on the Debug menu immediately following the Start menu.) After starting the application I can then successfully attach to the process and pick up debugging after the fact.

The key here is to know which process to attach to. If you are trying to debug a Windows application, you want to attach to the Windows process. If you are trying to debug an ASP.NET application, you can attach to the instance of Internet Explorer. After attaching, the debugger will stop on breakpoints and you can pick up debugging your application. Follow the numbered steps to attach to a running ASP.NET Web application and start debugging after the application is running.

  1. Open Internet Explorer and browse to your Web application (or click DebugStart without Debugging with the problematic project open ).

  2. Start VS .NET and open the project representing the Web site you are browsing.

  3. Set any breakpoints in your code-behind file where you want the debugger to pick up.

  4. Select DebugProcesses in VS .NET. From the Available Processes list select aspnet_wp.exe (ASP.NET Worker Process).

  5. Click Attach and OK in the Attach to Processes dialog.

  6. Close the Processes dialog.

When you perform an action that reaches a line of code with a breakpoint, the VS .NET debugger will break and the context will be switched to your code in VS .NET. (You can use the AttachDebugger.sln Web application to test attaching to a running process.)

TIP

A common cause of not being able to start with the debugger in ASP.NET applications is an error in the Web.config file. Double-check the Web.config file if the debugger won't start.

Attaching to a running process can be a useful trick when you are hot after a bug and can't start with debugging. Of course, you can restart VS .NET, restart IIS, or even reboot, but sometimes just getting the application started and debugging it will lead you to the problem that prevented starting with the debugger.



Visual Basic. NET Power Coding
Visual Basic(R) .NET Power Coding
ISBN: 0672324075
EAN: 2147483647
Year: 2005
Pages: 215
Authors: Paul Kimmel

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net