PRB: Error 406 Accessing an MTS Component in a Library Package

ID: Q233997


The information in this article applies to:


SYMPTOMS

When attempting to show a form from a Visual Basic client EXE after creating objects in a Microsoft Transaction Server (MTS) Library package, you may get the following error message:

"Run-time error '406': Non-modal forms cannot be displayed in this host application from an ActiveX DLL, ActiveX Control, or Property Page."

This message appears only when the compiled EXE is use - if the client application is run from the Visual Basic IDE the problem does not manifest itself/> The problem may also be detected as a changing App.NonModalAllowed property in the client EXE project.

In some situations (described in the MORE INFORMATION section) an Application Error can appear as well, which on Windows NT could have the following error message:
OleMainThreadWndName: [ProjectName.exe] - Application Error
The instruction at "[address]" referenced memory at "0x00000010". The memory could not be "read".


CAUSE

The objects in the MTS Library package are created in a Visual Basic 6 project marked as an Apartment Threaded.


RESOLUTION

Change the Threading Model value to "Single Threaded" on the ActiveX DLL project's Properties form, on the General tab. Recompile the ActiveX DLL and redeploy into the MTS package.


STATUS

Microsoft is aware of this problem. We will keep you updated by means of the Knowledge Base, MSDN articles, and other online resources.


MORE INFORMATION

When an MTS package is marked as "Library Package" in the Activation tab of the package's Properties form, the package will load into the client's process with the required ActiveX DLLs, as well as the required MTS runtime libraries.

This will happen as soon as your client application creates an object in the Package for the first time, either through an CreateObject() call, using the New keyword, or when a variable declared "As New" is used for the first time.

From this point forward the client program experiences the following behaviors:

Steps to Reproduce Behavior>

To reproduce this behavior use the following steps on a computer with MTS installed:
  1. Create the server component using Visual Basic 6.0. Create a new ActiveX DLL project including a class with the instancing property set to "5 - MultiUse". No methods are needed in the class. You can give the project the name "LibServer" and name the class "Class1".


  2. Set the threading model to "Apartment Threaded" and check "Unattended Execution", going to the General Tab on the property page for the project.


  3. Compile the DLL by selecting File..Make [Project Name].dll. You may now close Visual Basic.


  4. Create a new package and configure the ActiveX DLL to run in the package:

    Using the MTS Explorer MMC snap-in. Select the "Packages Installed" folder on My Computer, right click, select New..Package and select "Create An Empty Package". Give the package any name, select Next and then select Finish. Your package is now created. Select the Components folder for your package, and from Windows Explorer drag and drop the compiled DLL into the right pane on the MTS Explorer.
    Your component is now set to run within the MTS environment.


  5. Mark the package as a Library Package:
    Go to the Property page for the package and in the "Activation" tab select the option "Library Package".


  6. Create a client application:
    Load Visual Basic 6.0 and create a new Standard EXE project. On the From1 form created, add a command button and add the following code in its click event:


  7. 
       Private Sub Command1_Click()
        Dim o As Object
    
        MsgBox "App.NonModalAllowed = " & App.NonModalAllowed 'True!
    
        Set o = CreateObject("LibServer.Class1") 'The libraries are loaded
    
        MsgBox "App.NonModalAllowed = " & App.NonModalAllowed 'False!
    
        Form1.Show 'Error 406 and/or Access Violation.
       End Sub 
  8. Compile the Client application and execute it:
    Go to the File..Make [ProjectName].exe menu, and select OK.


  9. Run the EXE, the form should appear. A message displays stating "App.NonModalAllowed = True", then another one stating "App.NonModalAllowed = False" and then the error, probably followed by an Access Violation message.


The Access Violation only occurs only when: NOTE: You might want to delete the package, the DLL and the EXE generated after reproducing the problem.


REFERENCES

MTS 2.0 Online Help
For information on creating a Visual Basic application which uses components installed under Microsoft Transaction Server, please see the following article in the Microsoft Knowledge Base:

Q186342: HOWTO: Create a 3-Tier App Using VB, MTS and SQL Server

Additional query words: Error 406 VB6 MTS Library Package Modal Modeless Form Show Component DLL


Keywords          : kbMTS kbMTS200 kbMTSExplorer kbVBp600 kbDSupport 
Version           : WINDOWS:6.0; winnt:2.0
Platform          : WINDOWS winnt 
Issue type        : kbprb 

Last Reviewed: July 6, 1999