Microsoft KB Archive/836668

= You cannot use the Visual Studio .NET debugger or the Visual Studio 2005 debugger to debug COM components =

Article ID: 836668

Article Last Modified on 4/29/2007

-

APPLIES TO


 * Microsoft Visual Studio 2005 Professional Edition
 * Microsoft Visual Studio 2005 Standard 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

-



SYMPTOMS
In Microsoft Visual Studio .NET or in Microsoft Visual Studio 2005, when you debug a project that consumes a Microsoft Component Object Model (COM) component, you cannot use the Visual Studio .NET debugger or the Visual Studio 2005 debugger to debug the code that is contained in the COM component.



STATUS
This behavior is by design.



Create a COM component
Create a COM component by using Microsoft Visual Studio .NET or Microsoft Visual Studio 2005. To do this, follow these steps:  Start Microsoft Visual Studio .NET or Microsoft Visual Studio 2005. On the File menu, point to New, and then click Project. The New Project dialog box appears. Under Project Types, click Visual C++ Projects, and then under Templates, click ATL Project.

Note In Visual Studio 2005, click Visual C++. Type MyCom in the Name box, and then click OK. The ATL COM AppWizard dialog box appears. Click Finish. In Solution Explorer, right-click MyCom, point to Add, and then click Add Class. The Add Class - MyCom dialog box appears. Click ATL Control under Templates, and then click Open. The ATL Control Wizard - MyCom dialog box appears.</li> Type TestClass in the Short Name box, and then click Finish.</li> On the View menu, click Class View.</li> In Class View, right-click ITestClass, point to Add, and then click Add Method. The Add Method Wizard - MyCom dialog box appears.</li> Type TestMethod in the Method name box, and then click Finish.</li>  Add the following code in the TestMethod method: ::MessageBox(NULL, &quot;Hello World&quot;, &quot;Msg&quot;, 0); </li> On the Build menu, click Build Solution to build the project.</li></ol>

Create a client project
Create a client project by using Microsoft Visual Studio .NET 2003 or Visual Studio 2005. To do this, follow these steps: <ol> In Visual Studio .NET 2003 or Visual Studio 2005, point to New on the File menu, and then click Project.</li> Under Project Types, click Visual Basic Projects, and then under Templates, click Console Application.

Note In Visual Studio 2005, click Visual Basic.</li> Type MyApplication in the Name box, and then click OK.</li> In Solution Explorer, right-click References, and then click Add Reference.</li> Click the COM tab, and then click Browse to locate and to select the MyCom.dll file.</li> Click OK to close the Add Reference dialog box.</li>  Add the following line of code at the top of the Module1.vb file: Imports MYCOM </li>  In the Main method, add the following code: Dim objTestClass as new CTestClassClass ' Set the break point at this line of the code. objTestClass.TestMethod </li>  Select the following line of code, and then press F9. objTestClass.TestMethod </li> <li>On the Debug menu, click Start. The execution stops at the break point that was set in the step 9.</li> <li>Press F11 to debug the method of the COM component. You will notice that you cannot debug the method of the COM component.</li></ol>

<div class="references_section">