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.
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.
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 = 1000End Function
On the Project menu, click Project1 Properties.
Click the Compile tab, and then click to select No Optimization.
Click to select the Create Symbolic Debug Info check box.
Click the General tab, change Project Name to VB6DlltoCall, and then click OK.
On the File menu, click Make VB6DlltoCall.dll.
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.
On the Project menu, click VB6DlltoCall Properties.
Click the Component tab, click to select Binary Compatibility, and then click OK.
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.
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.
On the File menu, click Exit to close the Visual Basic 6.0 project.
Open the Visual Basic 6.0 folder that contains the DLL.
Right-click the DLL, and then click to select Properties.
Click the Security tab.
Click the Add button.
Type Computer Name\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 "Access Denied" error.
Verify that Read & Execute is checked for the ASP.NET account, and then click OK.
In the ASP.NET project, click the Project menu, and then click Add Reference.
Click Browse, and then click VB6DlltoCall.dll (created earlier).
Click Open, and then click OK.
Note In Visual Studio 2005, you do not have to click Open.
Add a button from the toolbox to Webform1.aspx.
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.showButtonValueEnd Sub
On the Build menu, click Build Solution.
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.
On the Debug menu, click Processes.
In the Processes dialog box, click to select aspnet_wp.exe under Available Processes, and then click Attach.
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.
Click OK, and then click Close.
Note When you click OK, the debugger may take up to five minutes to attach.
In the Visual Studio .NET or Visual Studio 2005 IDE, point to Open on the File menu, and then click File.
Click the Visual Basic 6.0 class file (VB6Class.cls), and then click Open.
Set a break point in the VB6Class.cls file on the following code line:
showButtonValue = 1000
Switch to the Web browser window that was open with the .aspx page when you clicked Start Without Debugging in step 7.
Click Button on the Webform.aspx page.
This hits the break point in the Visual Basic 6.0 class file.
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 Enterprise Edition for Windows 6.0, Microsoft ASP.NET 1.1, Microsoft ASP.NET 1.0