Microsoft KB Archive/278501

= PRB: Visual Basic MTS/COM+ Components Should Not Implement Class_Initialize =

Article ID: 278501

Article Last Modified on 6/12/2001

-

APPLIES TO


 * Microsoft Transaction Services 2.0
 * Microsoft COM+ 1.0
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q278501



SYMPTOMS
Code in the Class_Initialize method of a Visual Basic ActiveX dynamic-link library (DLL) can cause stability issues when the DLL is installed into Microsoft Transaction Server (MTS) or COM+ Services. In MTS, you may see one or both of the following events written to the Application event log:

Event ID: 4135

Source Transaction Server

Failed on creation within a server process. InitialBind (Package: YourPackage) (ProgId: YourClass.YourObject) (CLSID: {619FD1CF-2DA5-11D4-8A63-00A083360DAC}) (Interface: IClassFactory) (IID: {00000001-0000-0000-C000-000000000046}) (Method: 3) (Microsoft Transaction Server Internals Information: File: d:\viper\src\runtime\context\ccontext.cpp, Line: 2032)

Event ID 4129

Source Transaction Server

The run-time environment caught an exception during a call into your component. This error caused the process to terminate. ~CContext (Package: YourPackage) (ProgId: YourClass.YourObject) (CLSID: {619FD1CF-2DA5-11D4-8A63-00A083360DAC}) (Interface: IClassFactory) (IID: {00000001-0000-0000-C000-000000000046}) (Method: 4) (Microsoft Transaction Server Internals Information: File: d:\viper\src\runtime\context\ccontext.cpp, Line: 1104)



CAUSE
This problem occurs because the Visual Basic run time calls Class_Initialize before MTS creates the context wrapper for the component.



RESOLUTION
Do not implement Class_Initialize in an ActiveX DLL that you are going to install into MTS or COM+. If you need to initialize your object, use a separate initialization method or use the Activate method of the ObjectControl interface instead.



STATUS
This problem was corrected in Microsoft Windows 2000 Service Pack 1.

ObjectContext is now available for Class_Initialize and Class_Terminate.



MORE INFORMATION
In an MTS or COM+ component, the Class_Initialize and Class_Terminate events should not contain code that attempts to access the object or its corresponding context wrapper. The Visual Basic run-time environment calls Class_Initialize before the object and its context are activated. Therefore, any operation in Class_Initialize that attempts to access the object or its context wrapper will fail.

You may also see this behavior with code in the Class_Terminate method. MTS destroys the object and its context wrapper before the Visual Basic run time calls the Class_Terminate method, so code in this event handler can also cause stability issues.

ActiveX Data Objects (ADO) connections that are opened in Class_Initialize will not participate in an MTS or COM+ transaction, because transaction enlistment is controlled by the object context.

