PRB: No Option to Attach in Native Mode When the Native COM DLL Throws an Exception (822321)



The information in this article applies to:

  • Microsoft ASP.NET (included with the .NET Framework 1.1)

SYMPTOMS

When you call a Component Object Model (COM) DLL from server-side Microsoft Active Server Pages (ASP) code, you may receive an exception. The native code of the COM DLL throws this exception, and the Just-In-Time Debugging dialog box appears without an option to attach to the native mode.

CAUSE

This behavior is by design because Microsoft Internet Information Services (IIS) catches the native exception and then turns this exception into a script error.

WORKAROUND

To work around this problem, manually attach the Dllhost.exe process to the native mode. To work around this problem for the scenario that is mentioned in the "More Information" section of this article, follow these steps:
  1. In Microsoft Visual Studio .NET, open the Proj1 project.

    Note Proj1 is the name of the project that is created in the "More Information" section of this article.
  2. In Windows Explorer, locate the DllStore folder that is created in the "More Information" section of this article.
  3. Drag the Cal.cls file to Visual Studio .NET where the Proj1 project is open.
  4. In the Cal.cls file, set a breakpoint on the following statement:
    Function Divfunction(FirstNumber, SecondNumber)
  5. On the Debug menu, click Processes, and then select the Dllhost.exe process that has the Title field as Microsoft Active Server Pages.

    Note If the DLLHOST.EXE process is not available in the list of processes, click Start on the Debug menu to stop debugging.
  6. Click Attach.
  7. In the Attach to Process dialog box, click to select the Native check box , and then click OK.
  8. In the Processes dialog box, click Close.
  9. Visit the ASP page with the following URL:

    http://localhost/Proj1/Asp1.asp



    Notice that debugging breaks at the breakpoint that you have set in the Cal.cls file.

STATUS

This behavior is by design.

MORE INFORMATION

Steps to Reproduce the Behavior

Create a COM DLL

  1. Create a folder that is named DllStore to save your COM DLL.
  2. Start Microsoft Visual Basic 6.0.
  3. On the File menu, click New Project.
  4. In the New Project dialog box, click to select ActiveX DLL, and then click OK.
  5. On the View menu, click Properties Window.
  6. In the Properties window, click Class1 in the (Name) list, and then change the Name property to Cal.
  7. Add the following code to the Cal class:
    Public Num1 As Variant
    Public Num2 As Variant
    Function DivFunc(Num1, Num2)
        DivFunc = Num1 / Num2
    End Function
  8. On the Project menu, click Project1 Properties.
  9. Click the Compile tab, and then click to select the Create Symbolic Debug Info check box.
  10. Click the General tab, change Project Name to Computation, and then click OK.
  11. On the File menu, click Make Computation.dll.
  12. In the Make Project dialog box, locate the DllStore folder that you created in step 1, and then click OK to save the Computation.dll file.
  13. On the File menu, click Save Project As.
  14. In the Save File As dialog box, locate the DllStore folder that you created in step 1, and then click OK to save the Cal.cls file.
  15. In the Save Project As dialog box, click Save to save the Computation.vbp file.

Create an ASP.NET Project

  1. Start Visual Studio .NET.
  2. Create an ASP.NET Web Application project by using Microsoft Visual Basic .NET.

    Note In the Location text box, type the project name as http://localhost/Proj1.
  3. In Solution Explorer, right-click Proj1, point to Add, and then click Add New Item.
  4. In the Name text box, type Asp1.asp, and then click Open.
  5. Replace the existing code in the Asp1.asp file with the following code:
    <HTML>
    <TITLE>Test asp </TITLE>
    <BODY>
    <%
        Dim finalanswer
        Dim addthis 
        Set addthis=Server.CreateObject("Computation.Cal")    
        finalanswer=addthis.DivFunc(15,0) 
        Response.write finalanswer  
    %>
    <BODY>
    <HTML>
    
  6. In Solution Explorer, right-click References, and then click Add Reference.
  7. Locate and then select the Computation.dll file that you created earlier, and then click Open.
  8. Click OK to add a reference to the Computation.dll file.
  9. On the Build menu, click Build Solution.
  10. In Solution Explorer, right-click Asp1.asp, and then click Set As Start Page.
  11. On the Debug menu, click Start.

    The Just-In-Time Debugging dialog box appears that is mentioned in the "Symptoms" section of this article.
  12. When you click OK in the Just-In-Time Debugging dialog box, an Attach to Process dialog box that does not have the option to attach to the native mode appears.

REFERENCES

For additional information, click the following article numbers to view the articles in the Microsoft Knowledge Base:

170946 HOWTO: Create and Use a Minimal ActiveX Component in VB

303845 HOWTO: Create or Open a Visual Studio .NET Project in the Root Web


Modification Type:MajorLast Reviewed:10/17/2003
Keywords:kbCOMInterop kbDLL kbDebug kbprb KB822321 kbAudDeveloper