Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

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


View products that this article applies to.

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.


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

Create the Visual Basic 6.0 DLL

  1. In the Visual Basic 6.0 IDE, click New Project on the File menu.
  2. In the New Project dialog box, click to select ActiveX DLL, and then click OK.
  3. On the View Menu, click Properties.
  4. On the Properties dialog box drop-down list, click Class1.
  5. Change the Name property to VB6Class.
  6. Add the following code to your class to create a public method in your class:
    Public Function showButtonValue() As Integer
        showButtonValue = 1000
    End Function
    
  7. On the Project menu, click Project1 Properties.
  8. Click the Compile tab, and then click to select No Optimization.
  9. Click to select the Create Symbolic Debug Info check box.
  10. Click the General tab, change Project Name to VB6DlltoCall, and then click OK.
  11. On the File menu, click Make VB6DlltoCall.dll.
  12. 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.
  13. On the Project menu, click VB6DlltoCall Properties.
  14. Click the Component tab, click to select Binary Compatibility, and then click OK.
  15. 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.
  16. 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.
  17. On the File menu, click Exit to close the Visual Basic 6.0 project.
  18. Open the Visual Basic 6.0 folder that contains the DLL.
  19. Right-click the DLL, and then click to select Properties.
  20. Click the Security tab.
  21. Click the Add button.
  22. 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.
  23. Click OK.
  24. Verify that Read & Execute is checked for the ASP.NET account, and then click OK.

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://localhost/MyASPnetProject.

    Note In the project name, http://localhost creates the application on your local server.
  5. 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://localhost/MyASPnetProject.

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

Debug

  1. In the ASP.NET project, click the Project menu, and then click Add Reference.
  2. Click Browse, and then click VB6DlltoCall.dll (created earlier).
  3. Click Open, and then click OK.

    Note In Visual Studio 2005, you do not have to click Open.
  4. Add a button from the toolbox to Webform1.aspx.
  5. 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
  6. On the Build menu, click Build Solution.
  7. 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.
  8. On the Debug menu, click Processes.
  9. In the Processes dialog box, click to select aspnet_wp.exe under Available Processes, and then click Attach.
  10. 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.
  11. Click OK, and then click Close.

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

    This hits the break point in the Visual Basic 6.0 class file.

↑ Back to the top


References

For additional information, click the following article numbers to view the articles in the Microsoft Knowledge Base:
170946 How To Create and Use a Minimal ActiveX Component in VB


303845 How To Create or Open a Visual Studio .NET Project in the Root Web

↑ Back to the top


Keywords: kbvs2005applies, kbwebforms, kbdll, kbcominterop, kbweb, kbdebug, kbhowtomaster, kbvs2005swept, KB811658

↑ Back to the top

Article Info
Article ID : 811658
Revision : 8
Created on : 12/6/2006
Published on : 12/6/2006
Exists online : False
Views : 508