BUG: AV Running VB-Built Component in Multi-Threaded Environment

ID: Q186273


The information in this article applies to:
  • Microsoft Visual Basic Professional and Enterprise Editions for Windows, versions 5.0, 6.0
  • Microsoft Visual Studio versions 97, 97sp1, 97sp2, 97sp3


SYMPTOMS

When running an apartment model ActiveX DLL created in Visual Basic in a multithreaded environment such as Microsoft Internet Information Server (IIS) or Microsoft Transaction Server (MTS), COM+, Internet Explorer, ActiveX EXEs, and so on, the DLL fails periodically with an access violation (AV).


RESOLUTION

The following steps may be used to change the DLL to avoid the problem. This may not resolve the issue in all cases.

Step-by-Step Example

  1. Add a class module to the project.


  2. Set the name of the class to clsEmpty.


  3. Set the Instancing property of the class to 2-PublicNotCreatable.


  4. In Project Properties, set the Start Up Object to Sub Main.


  5. Add a BAS module, or put the following in an existing BAS module in the project:
    
          Public gEmpty As clsEmpty
          Public Sub main()
             Set gEmpty = New clsEmpty
          End Sub
     


  6. Save the project and recompile.


  7. If you are running Visual Basic 6.0:

  8. On the General tab in the Project Properties dialog box, set the project options for optimal performance: select Unattended Execution and Retain in Memory.

    NOTE: The Unattended Execution option is not available if the project contains any user interface elements, such as forms or controls. The Retain in Memory option is not available if Unattended Execution is not selected.

    NOTE: Prior to Service Pack 3 for Visual Studio 6.0, it was possible to get an AV during process shutdown with Retain in Memory enabled. This has been fixed in Visual Studio 6, Service Pack 3.

    For additional information on access violation on process shutdown, click the article number below to view the article in the Microsoft Knowledge Base:
    Q214755 BUG: VB 6 DLL Settings Cause Access Violation During MTS Shutdown



STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.


MORE INFORMATION


REFERENCES

For additional information on errors when using an ActiveX DLL created in Visual Basic 5.0 that contains a For... Each loop that iterates through a Visual Basic collection, click the article number below to view the article in the Microsoft Knowledge Base:

Q183164 FIX: For..Each Loop in ActiveX Component Causes Errors
For additional information on access violation on process shutdown, click the article numbers below to view the articles in the Microsoft Knowledge Base:
Q214755 FIX: VB 6 DLL Settings Cause Access Violation During MTS Shutdown
Q191119 FIX: VB Classes Can Cause IIS to Have Access Violations
For information on Visual Studio, Service Pack 3, please see the Web site at the following location:

Visual Studio 6.0, Service Pack 3
For additional information on threading issues with Visual Basic 6.0 ActiveX components, click the article number below to view the article in the Microsoft Knowledge Base:
Q241896 PRB: Threading Issues with Visual Basic 6.0 ActiveX Components

Additional query words: MTS IIS crash gpf ipf

Keywords : kbVBp500bug kbVBp600bug kbVS97bug kbVS97sp1bug kbVS97sp2bug kbVS97sp3bug kbGrpVB kbDSupport
Version : WINDOWS:5.0,6.0,97,97sp1,97sp2,97sp3
Platform : WINDOWS
Issue type : kbbug


Last Reviewed: January 18, 2000
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.