Microsoft KB Archive/919519

= How to debug a COM+ component by using Visual Studio 2005 or by using Visual Studio .NET =

Article ID: 919519

Article Last Modified on 11/22/2007

-

APPLIES TO


 * Microsoft Visual Studio 2005 Team System Architect Edition
 * Microsoft Visual Studio 2005 Team System Developer Edition
 * Microsoft Visual Studio 2005 Team System Test Edition
 * Microsoft Visual Studio 2005 Team Foundation
 * Microsoft Visual Studio 2005 Standard Edition
 * Microsoft Visual Studio 2005 Professional Edition
 * Microsoft Visual Studio .NET 2003 Professional Edition
 * Microsoft Visual Studio .NET 2003 Enterprise Architect
 * Microsoft Visual Studio .NET 2003 Enterprise Developer
 * Microsoft Visual Studio .NET 2003 Academic Edition
 * Microsoft Visual Studio .NET 2002 Professional Edition
 * Microsoft Visual Studio .NET 2002 Enterprise Architect
 * Microsoft Visual Studio .NET 2002 Enterprise Developer
 * Microsoft Visual Studio .NET 2002 Academic Edition

-





SUMMARY
''This article describes how to debug a COM+ component by using Microsoft Visual Studio 2005 or by using Microsoft Visual Studio .NET. Additionally, this article describes how to debug a COM+ component that is installed on the same computer as the client application and how to debug a COM+ component that is installed on a remote computer.''



INTRODUCTION
This article describes how to debug a COM+ component by using Visual Studio 2005 or by using Visual Studio .NET. You can use a COM+ component in the following environments:
 * You can use a COM+ component that is installed on the same computer as the client application. This is a local COM+ component.
 * You can use a COM+ component that is installed on a different computer from the client application. This is a remote COM+ component.

Additionally, a COM+ component can use unmanaged code or managed (Microsoft .NET) code. This article includes the steps to debug all these types of COM+ components.



How to debug a local COM+ component
A local COM+ component is installed on the same computer as the client application. To debug a local COM+ component, use the following procedures.

Prerequisites
Before you try to debug a local COM+ component, make sure that you have the following items:
 * A COM+ application installed on the local computer
 * A COM+ component (DLL) installed in the COM+ application

Note You must build the DLL in debug mode before you add the DLL to the COM+ application.
 * The source files for the COM+ component

Note The source files must match the running build of the COM+ component.
 * The symbolic debugging information for the COM+ component

Note The symbolic debugging information is contained in the .pdb file for the project.
 * A client application that creates an instance of the local COM+ component and that calls a method or a property of the local COM+ component
 * The source files for the client application
 * The symbolic debugging information for the client application

Note The symbolic debugging information is contained in the .pdb file for the project.

Set up the debugging files
Copy the source files and the symbolic debugging information (the .pdb file) for the COM+ component into the same folder. Therefore, the files will be easier to locate when you set up the Visual Studio environment.

Set up the Visual Studio environment
 Start Visual Studio 2005, or start Visual Studio .NET. In Visual Studio 2005, point to Open on the File menu, and then click Project/Solution.

In Visual Studio .NET, point to Open on the File menu, and then click Project. Locate the project that contains the client application, and then click Open. In Solution Explorer, right-click the solution, and then click Properties. Expand Common Properties, and then click Debug Source Files. Click New Line.</li> Click the ellipsis button (...).</li> Locate the directory where the source files for the COM+ component are located, and then click Open.</li> Set up the debug symbol files for the COM+ component. To do this in Visual Studio 2005, follow these steps: <ol style="list-style-type: lower-alpha;"> In the Solution Property Pages dialog box, click OK.</li> On the Tools menu, click Options.</li> Expand Debugging, and then click Symbols.</li> Click New Line.</li> Type the path of the folder where the .pdb file for the COM+ component is located, and then click OK.</li></ol>

To do this in Visual Studio .NET, follow these steps: <ol style="list-style-type: lower-alpha;"> In the Solution Property Pages dialog box, click Debug Symbol Files.</li> Click New Line.</li> Click the ellipsis button (...).</li> Locate the folder where the .pdb file for the COM+ component is located, and then click Open.</li> Click OK.</li></ol> </li> Add a breakpoint in the client application code where you create an instance of the local COM+ component.</li> On the File menu, point to Open, and then click File.</li> Locate the source files for the COM+ component, and then click Open.</li> <li>Add a breakpoint in the COM+ component source code where you want the Visual Studio debugger to stop.</li></ol>

Debug the local COM+ component
<ol> <li>Start the Visual Studio debugger. To do this in Visual Studio 2005, click Start Debugging on the Debug menu.

To do this in Visual Studio .NET, click Start on the Debug menu.</li> <li>When the Visual Studio debugger reaches the breakpoint in the client application, step into the code. To do this, click Step Into on the Debug menu.</li> <li>When the instance of the COM+ component is created, attach to the Dllhost.exe process. To do this in Visual Studio 2005, follow these steps: <ol style="list-style-type: lower-alpha;"> <li>On the Debug menu, click Attach to Process.</li> <li>Click Dllhost.exe, and then click Attach.</li></ol>

To do this in Visual Studio .NET, follow these steps: <ol style="list-style-type: lower-alpha;"> <li>On the Debug menu, click Processes.</li> <li>Click Dllhost.exe, and then click Attach.</li></ol> </li> <li>In Visual Studio .NET, select the type of code to debug by using one of the following methods: <ul> <li>If the COM+ component uses unmanaged code, click to select the Native check box, click OK, and then click Close.</li> <li>If the COM+ component uses managed code, click to select the Common Language Runtime check box, click OK, and then click Close.</li></ul>

Note This step is not required in Visual Studio 2005. Visual Studio 2005 automatically determines the type of code to debug.</li> <li>On the Debug menu, click Continue.

Notice that the Visual Studio debugger reaches the breakpoint that you set in the COM+ component source code.</li> <li>On the Debug menu, click Continue.

When the Visual Studio debugger leaves the COM+ function, you receive the following message:

No symbols are loaded for any call stack frame. The source code cannot be displayed.

</li> <li>Click OK.</li> <li>On the Debug menu, click Continue.

The Visual Studio debugger reaches the end of the client application code, and the Visual Studio debugger stops running.</li> <li>On the Debug menu, click Detach All.</li></ol>

How to debug a remote COM+ component
A remote COM+ component is installed on a different computer from the client application. When you debug a remote COM+ component, you must run the following instances of the Visual Studio debugger:
 * An instance of the Visual Studio debugger for the client application
 * An instance of the Visual Studio debugger for the remote COM+ component

Note This instance of Visual Studio attaches to the Dllhost.exe process that is running on the remote computer.

To debug a remote COM+ component, use the following procedures.

Prerequisites
Before you try to debug a remote COM+ component, make sure that you have the following items: <ul> <li>A COM+ application installed on the remote computer</li> <li>A COM+ component (DLL) installed in the COM+ application

Note You must build the DLL in debug mode before you add the DLL to the COM+ application.</li> <li>The source files for the COM+ component

Note The source files must match the running build of the COM+ component.</li> <li>The symbolic debugging information for the COM+ component

Note The symbolic debugging information is contained in the .pdb file for the project.</li> <li>The correct remote debugging setup

Note This includes the correct security settings on the remote computer that is hosting the COM+ component. For more information about how to set up remote debugging, visit the following Microsoft Developer Network (MSDN) Web site:

http://msdn2.microsoft.com/en-us/library/y7f5zaaa(vs.71).aspx

</li> <li>A client application that creates an instance of the remote COM+ component and that calls a method or a property of the remote COM+ component</li> <li>The source files for the client application</li> <li>The symbolic debugging information for the client application

Note The symbolic debugging information is contained in the .pdb file for the project.</li></ul>

Set up the debugging files
On the remote computer, copy the symbolic debugging information (the .pdb file) for the COM+ component into the same folder where the DLL is located.

Start an instance of the Visual Studio debugger for the client application

 * 1) Start Visual Studio 2005, or start Visual Studio .NET.
 * 2) In Visual Studio 2005, point to Open on the File menu, and then click Project/Solution.

In Visual Studio .NET, point to Open on the File menu, and then click Project.
 * 1) Locate the project that contains the client application, and then click Open.
 * 2) Add a breakpoint in the client application code where you call a method or a property of the remote COM+ component.
 * 3) Start the Visual Studio debugger. To do this in Visual Studio 2005, click Start Debugging on the Debug menu.

To do this in Visual Studio .NET, click Start on the Debug menu.

Note The Visual Studio debugger stops at the breakpoint that you added in step 4.

Start an instance of the Visual Studio debugger for the remote COM+ component
<ol> <li>Start Visual Studio 2005, or start Visual Studio .NET.</li> <li>Attach to the Dllhost.exe process. To do this in Visual Studio 2005, follow these steps: <ol style="list-style-type: lower-alpha;"> <li>On the Tools menu, click Attach to Process.</li> <li>In the Qualifier box, type the name of the remote computer where the COM+ component is installed.</li> <li>Click Refresh.</li> <li>Click Dllhost.exe, and then click Attach.</li></ol>

To do this in Visual Studio .NET, follow these steps: <ol style="list-style-type: lower-alpha;"> <li>On the Tools menu, click Debug Processes.</li> <li>In the Name box, type the name of the remote computer where the COM+ component is installed.</li> <li>Click Refresh.</li> <li>Click Dllhost.exe, and then click Attach.</li></ol> </li> <li>In Visual Studio .NET, select the type of code to debug by using one of the following methods: <ul> <li>If the COM+ component uses unmanaged code, click to select the Native check box, click OK, and then click Close.</li> <li>If the COM+ component uses managed code, click to select the Common Language Runtime check box, click OK, and then click Close.</li></ul>

Note This step is not required in Visual Studio 2005. Visual Studio 2005 automatically determines the type of code to debug.</li> <li>Set up the debug symbol files for the COM+ component. To do this in Visual Studio 2005, follow these steps: <ol style="list-style-type: lower-alpha;"> <li>On the Tools menu, click Options.</li> <li>Expand Debugging, and then click Symbols.</li> <li>Click New Line.</li> <li>Type the path of the folder on the remote computer where the .pdb file for the COM+ component is located, and then click OK.</li></ol>

To do this in Visual Studio .NET, follow these steps: <ol style="list-style-type: lower-alpha;"> <li>In Solution Explorer, right-click the solution, and then click Properties.</li> <li>Expand Common Properties, and then click the Debug Symbol Files tab.</li> <li>Click New Line.</li> <li>Click the ellipsis button (...).</li> <li>Type the path of the folder on the remote computer where the .pdb file for the COM+ component is located, and then click OK.</li></ol> </li> <li>On the Debug menu, click Break All.</li> <li>On the Debug menu, point to Windows, and then click Modules.</li> <li>In the list, locate the DLL for the COM+ component.</li> <li>In Visual Studio 2005, confirm that the Symbol Status column displays Symbols loaded.

In Visual Studio .NET, confirm that the Information column displays Symbols loaded.

Note If the Symbol Status column or the Information column displays No symbols loaded, right-click the DLL for the COM+ component, and then click Load Symbols. If you are prompted for the path of the symbols, locate the folder on the remote computer where the .pdb file is located, and then click Open.</li> <li>On the Debug menu, click Continue.</li> <li>On the File menu, point to Open, and then click File.</li> <li>Locate the source files for the COM+ component, and then click Open.</li> <li>Add a breakpoint in the COM+ component source code where you want the Visual Studio debugger to stop.</li></ol>

Debug the remote COM+ component

 * 1) Switch to the instance of the Visual Studio debugger for the client application.
 * 2) On the Debug menu, click Continue.
 * 3) Switch to the instance of the Visual Studio debugger for the remote COM+ component.

Notice that the Visual Studio debugger reaches the breakpoint that you set in the COM+ component source code.

<div class="references_section">