Microsoft KB Archive/233997

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

Article ID: 233997

Article Last Modified on 6/18/2001

-

APPLIES TO


 * Microsoft Transaction Services 2.0
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q233997



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 used. 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:

 The App.NonModalAllowed property changes from True to False,  When a form is tried to be shown non-modally the Error 406 described above occurs. This happens when either using frm.Show or frm.Show vbModeless where frm is the form name or a form variable. Also, if the Error 406 is not trapped the application may crash with the message described in SYMTOMS section. This could happen immediately or when the program ends. 

Steps to Reproduce Behavior>
To reproduce this behavior use the following steps on a computer with MTS installed:  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". Set the threading model to "Apartment Threaded" and check "Unattended Execution", going to the General Tab on the property page for the project.</li> Compile the DLL by selecting File..Make [Project Name].dll. You may now close Visual Basic.</li> 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.</li> 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".</li>  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: 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 </li> Compile the Client application and execute it:

Go to the File..Make [ProjectName].exe menu, and select OK.</li> 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.</li></ol>

The Access Violation only occurs only when:
 * The ActiveX DLL is marked for "Unattended Execution", clearing this flag causes the Access Violation to disappear (only Error 406 remains)
 * Error 406 is not handled, adding an On Error.. statement and the appropriate handler would trap the 406 error and continue executing the application.

NOTE: You might want to delete the package, the DLL and the EXE generated after reproducing the problem.

<div class="references_section">