Microsoft KB Archive/811658

= How to use the Visual Studio .NET or Visual Studio 2005 native debugger to debug a Visual Basic 6.0 DLL when it is called from an ASP.NET application =

Article ID: 811658

Article Last Modified on 12/6/2006

-

APPLIES TO


 * Microsoft Visual Basic 2005
 * Microsoft Visual Basic .NET 2003 Standard Edition
 * Microsoft Visual Basic .NET 2002 Standard Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition
 * Microsoft ASP.NET 1.1
 * Microsoft ASP.NET 1.0

-



IN THIS TASK

 * SUMMARY
 * Requirements
 * Create the Visual Basic 6.0 DLL
 * Create the ASP.NET
 * Debug
 * REFERENCES



SUMMARY
This step-by-step article describes how to use the Microsoft Visual Studio .NET or Microsoft Visual Studio 2005 native debugger to debug a Microsoft Visual Basic 6.0 DLL when it is called from an ASP.NET application.

To debug Visual Basic applications, use one of the following methods:
 * Use the Visual Basic development environment.

When you debug in the development environment, you use P-code. P-code is an interpreted language that permits you to debug in the development environment.

-or-
 * Use the native debugger if problems do not appear when you debug in the Visual Basic development environment, but problems do appear in the compiled version.

This article describes how to use the second method to debug a Visual Basic 6.0 DLL that is being used in ASP.NET. You debug the DLL by using the same binary that the DLL runs with (not including any optimizations). This creates an execution that is easier to debug than the P-code that you receive when you debug in the Visual Basic development environment.

back to the top

Requirements
The following list outlines the recommended hardware, software, network infrastructure, and service packs that are required:
 * Microsoft Visual Studio .NET or Microsoft Visual Studio 2005
 * Microsoft Visual Basic 6.0
 * Microsoft Internet Information Services (IIS) 5.0 or later

This article assumes that you are familiar with the following topics:
 * Microsoft Visual Basic .NET or Microsoft Visual Basic 2005 syntax
 * Microsoft Visual Basic 6.0 syntax
 * Microsoft Visual Studio .NET or Microsoft Visual Studio 2005 environment

back to the top

Create the Visual Basic 6.0 DLL
 In the Visual Basic 6.0 IDE, click New Project on the File menu. In the New Project dialog box, click to select ActiveX DLL, and then click OK. On the View Menu, click Properties. On the Properties dialog box drop-down list, click Class1. Change the Name property to VB6Class .  Add the following code to your class to create a public method in your class: Public Function showButtonValue As Integer showButtonValue = 1000 End Function  On the Project menu, click Project1 Properties.</li> Click the Compile tab, and then click to select No Optimization.</li> Click to select the Create Symbolic Debug Info check box.</li> Click the General tab, change Project Name to VB6DlltoCall, and then click OK.</li> On the File menu, click Make VB6DlltoCall.dll.</li> Click to select the Visual Basic 6.0 folder, and then click OK to save VB6DlltoCall.dll.

Note Your Visual Basic 6.0 project is stored in the Visual Basic 6.0 folder.</li> On the Project menu, click VB6DlltoCall Properties.</li> Click the Component tab, click to select Binary Compatibility, and then click OK.</li> On the File menu, click Save Project, and then click the Visual Basic 6.0 folder to save the class and project file.

Note VB6Class.cls is the name of the class file that you debug. Therefore, you can just accept the default names.</li> On the File menu, click Make VB6DlltoCall.dll.

Note When you create the file a second time, you receive a message about overwriting the existing file. Permit the compiler to overwrite the existing DLL.</li> On the File menu, click Exit to close the Visual Basic 6.0 project.</li> Open the Visual Basic 6.0 folder that contains the DLL.</li> Right-click the DLL, and then click to select Properties.</li> Click the Security tab.</li> Click the Add button.</li> Type \ASPNET, and then click Check Name to verify that you locate the ASP.NET account.

Note Replace Computer Name with the name of your computer. The ASP.NET account is the user account that the ASP.NET worker process executes under. If you do not permit this account to execute your DLL, your class is not created, and it fails with an &quot;Access Denied&quot; error.</li> Click OK.</li> <li>Verify that Read & Execute is checked for the ASP.NET account, and then click OK.</li></ol>

back to the top

Create the ASP.NET Project in Visual Studio .NET

 * 1) Start Visual Studio .NET.
 * 2) On the File menu, point to New, and then click Project.
 * 3) In the New Project dialog box, click to select Visual Basic Projects under Project Types, and then click to select ASP.NET Web Application under Templates.
 * 4) In the Location text box, type the project name as http:// /.

Note In the project name, http://  creates the application on your local server.
 * 1) Click OK to create the project.

Create the ASP .NET 2.0 Project in Visual Studio 2005

 * 1) Start Visual Studio 2005.
 * 2) On the File menu, point to New, and then click Web Site.
 * 3) In the New Web Site dialog box, click ASP .NET Web Site under Templates.
 * 4) In the Location box, click HTTP, and then type the project name as http:// /.

Note In the project name, http://  creates the application on your local server.
 * 1) Click Visual Basic in the Language box, and then click OK to create the project.

back to the top

Debug
<ol> <li>In the ASP.NET project, click the Project menu, and then click Add Reference.</li> <li>Click Browse, and then click VB6DlltoCall.dll (created earlier).</li> <li>Click Open, and then click OK.

Note In Visual Studio 2005, you do not have to click Open.</li> <li>Add a button from the toolbox to Webform1.aspx.</li> <li> Double-click Button, and then add the following code to the Button1_Click event in Webform1.aspx.vb: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim cls As New VB6DlltoCall.VB6ClassClass Button1.Text = cls.showButtonValue End Sub </li> <li>On the Build menu, click Build Solution.</li> <li>On the Debug menu, click Start Without Debugging.

Note Start the application that you created one time without debugging to make sure that the ASP.NET worker process is started, and that you can attach to the worker process in the next step.</li> <li>On the Debug menu, click Processes.</li> <li>In the Processes dialog box, click to select aspnet_wp.exe under Available Processes, and then click Attach.</li> <li>In the Attach to Process dialog box, click to select the Native check box and the Common Language Runtime check box.

Note If you do not have the native debugging option, you do not have Microsoft Visual C++ .NET or Microsoft Visual C++ 2005 installed. You must install Visual C++ .NET or Visual C++ 2005 for the debugging to work correctly.</li> <li>Click OK, and then click Close.

Note When you click OK, the debugger may take up to five minutes to attach.</li> <li>In the Visual Studio .NET or Visual Studio 2005 IDE, point to Open on the File menu, and then click File.</li> <li>Click the Visual Basic 6.0 class file (VB6Class.cls), and then click Open.</li> <li> Set a break point in the VB6Class.cls file on the following code line: showButtonValue = 1000 </li> <li>Switch to the Web browser window that was open with the .aspx page when you clicked Start Without Debugging in step 7.</li> <li>Click Button on the Webform.aspx page.

This hits the break point in the Visual Basic 6.0 class file.</li></ol>

back to the top

<div class="references_section">