... about Brad

Monday, July 26, 2004

Debugging your .NET components

There are two options for your .NET components.  You can debug in design-time mode or in run-time mode. 

 

To debug in design-time mode you will start with two instances of Visual Studio.  The first will have your custom component and the second will have your custom code that tests the component.  Then do the following:

a.     Click on the Debug menu in Visual Studio containing your component code and select the Process menu item.

b.     When the Available Processes dialog opens find and select the devenv.exe process with the title of your Visual Studio project containing the test code.

c.     Click on the Attach button.

d.     When the Attach to Process dialog appears click the checkbox next to the Common Language Runtime and hit the OK button.  Click on the Close button on the Process dialog box.

e.     Place a breakpoint on the appropriate method in your component code.

f.      Go back to the instance of Visual Studio containing your test code and open it in the designer.

g.     From this point you can either click on the component itself or if your component exposes properties, you can click on the property in the property page and you will enter break mode and be placed where you applied your breakpoint.

 

To debug in run-time mode we actually do this two ways.  The first is simple and familiar.  Add the test project to the solution of the component project and debug.  The second is to keep the projects separate, for whatever reasons you may have. We will follow almost the same steps as we did during design-time mode except that we will attach to the aspnet_wp.exe process instead.  In addition, when debugging in run-time mode we only need one instance of Visual Studio which contains your custom code. To setup debugging follow these steps:

    1. Open the webform that will be running your component in IE.
    2. Click on the Debug menu is Visual Studio and select the Process menu item.
    3. When the Available Processes dialog opens find and select the aspnet_wp.exe process.
    4. Click on the Attach button.
    5. When the Attach to Process dialog appears click the checkbox next to the Common Language Runtime and hit the OK button.  Click on the Close button on the Process dialog box.
    6. Place a breakpoint on the appropriate method in your component code.  
    7. Submit a postback in order to invoke this component.
    8. Your project will enter break mode and you will be placed where you applied your breakpoint.

0 Comments:

Post a Comment

Links to this post:

Create a Link

<< Home