Debugging a Server Control


To debug a server control, you must attach a debugger to an application that uses the server control because server controls are compiled into libraries, while a debugger can be attached only to an executable.

You can debug a server control using the debugging capabilities of the Visual Studio .NET IDE, or, if you have the .NET Framework SDK alone, you can use the graphical debugger DbgClr or the command-line debugger, CorDbg.

To debug a control in Visual Studio .NET, perform the following steps:

  1. Create a solution that contains these projects: a class library that contains the control you want to debug and a Web application that contains a Web Forms page that uses your control. Make sure that you have enabled debugging by specifying the Debug="true" attribute in the Page directive at the top of the page.

  2. Set breakpoints in the source code for your control and build the solution.

  3. In Solution Explorer, right-click the page that uses your control and click Set As Start Page.

  4. From the Debug menu, click Start (or press F5 on the keyboard) to start debugging.

    The debugger will stop at the first breakpoint in the code for your control. From there on, you can perform normal debugging operations such as stepping into code and inspecting variables .

The graphical debugger that ships with the .NET Framework SDK, DbgClr, provides the same debugging capabilities as Visual Studio .NET. However, you must manually perform the steps to compile your controls library, to load your Web application and to attach the debugger to the Web application.

To debug a server control using the DbgClr graphical debugger, perform the following steps:

  1. Compile your control using the /debug option. This generates the assembly (.dll) and the program database (.pdb) file that contains debugging information.

  2. Create a Web application and copy the .dll and .pdb files to your Web application's bin directory.

  3. Create an ASP.NET page that uses the control you want to debug and place it within your Web application. (This step is not needed if your Web application already contains a page or pages that use your control.) Make sure that you have enabled debugging on the page by specifying the Debug="true" attribute in the Page directive at the top of the page.

  4. Start the debugger by opening the FrameworkSDK\GuiDebug directory in Windows Explorer and double-clicking DbgClr.exe.

    From the File menu click Open to browse to the file that contains the source code for the control you want to debug, and open that file.

  5. Set breakpoints in the source code of your control.

  6. From the Debug menu click Debug Processes. This will launch the Processes dialog box, which displays running processes to which you can attach the debugger.

  7. Click aspnet_wp.exe to select the ASP.NET worker process and click the Attach button on the right to attach the debugger to it. In Windows .NET Server, you should attach to the IIS worker process, w3wp.exe, which replaces the ASP.NET worker process.

  8. Click the Close button in the upper right corner of the Processes dialog box to close the dialog box.

  9. Open a browser window and request a page that uses your control.

    The debugger will stop at the first breakpoint in the code for your control. From there on you can perform normal debugging operations.



Developing Microsoft ASP. NET Server Controls and Components
Developing Microsoft ASP.NET Server Controls and Components (Pro-Developer)
ISBN: 0735615829
EAN: 2147483647
Year: 2005
Pages: 183

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