Microsoft KB Archive/811445

= Using COMTI user-defined types with .NET and Visual Studio .NET =

Article ID: 811445

Article Last Modified on 12/4/2007

-

APPLIES TO


 * Microsoft Host Integration Server 2000 Standard Edition
 * Microsoft Host Integration Server 2000 Service Pack 1
 * Microsoft SNA Server 4.0
 * Microsoft SNA Server 4.0 Service Pack 1
 * Microsoft SNA Server 4.0 Service Pack 2
 * Microsoft SNA Server 4.0 Service Pack 3
 * Microsoft SNA Server 4.0 Service Pack 4
 * Microsoft Host Integration Server 2004 Standard Edition

-



SUMMARY
This article lists the options that are available when you use COM Transaction Integrator (COMTI) User Defined Types (UDTs) or Host Integration Server (HIS) 2004 TI COM UDTs with the .NET Framework and Visual Studio .NET.

Note: Host Integration Server 2004 TI uses .NET Framework 1.1.



MORE INFORMATION
COMTI and HIS 2004 TI COM support the use of user-defined types for parameters and return values. A few things to note about user-defined types:
 * In COMTI, they are defined by using the COMTI Component Builder application.
 * In HIS 2004 TI, they are defined using the TI Designer within Visual Studeio .NET 2003.
 * They work very well in a Visual Basic 6 development environment.
 * They also work well in a Visual C++ 6 development environment.

However, by default, user-defined types do not work in an application that is based on the .NET Framework, version 1.0. For example, if a UDT is passed to COMTI by a .NET-based application, the following error will be logged by COMTI: (102) COM Transaction Integrator reported the following exception to the client:

Component: TestUDT.TestUDT.1

Method: Method1

Exception description:

(1205) COM Transaction Integrator detected an error on parameter 1 prior to the remote operation. COM Transaction Integrator could not convert from variant type (0x4009) to (0x401d) (0x80020008). Contact the application programmer. Install the correct component library for this component in Microsoft Transaction Server.

This call does not work because the COM Interop layer of the .NET Framework 1.0 marshals the user-defined type as a VT_DISPATCH type instead of as a VT_RECORD type or VT_USERDEFINED type.

To successfully use COMTI user-defined types with a .NET Framework 1.0 application, that application must implement a custom marshaller. This means that the application must build the VT_RECORD structure itself before handing it off to COMTI. This type of coding requires advanced knowledge of COM and .NET data types and marshaling between those types.

In next release of the .NET Framework (version 1.1), the COM Interop layer automatically marshals user-defined types as VT_RECORD types. This means that .NET Framework 1.1 applications can use COMTI and user-defined types without implementing any custom marshaling.

The next release of Visual Studio .NET (Visual Studio .NET 2003) uses this new version of the framework. Therefore, applications that are written by using Visual Studio .NET 2003 can also use COMTI and user-defined types without any extra coding.

To use a COMTI or HIS 2004 TI COM type library from a .NET Framework 1.1 application, follow these steps:
 * Create a .NET Interop Assembly for the type library. To do this, you can use either the TLB Importer Utility (Tlbimp.exe) or the Add Reference dialog box in Visual Studio .NET 2003.
 * Register the newly created .NET Interop Assembly by using the Register Assembly Utility (Regasm.exe). If the .NET Interop Assembly is not registered, the calling application can pass user-defined types but will receive an exception when COMTI or HIS 2004 TI tries to pass a user-defined type back to the calling application.
 * Add a reference to the .NET Interop Assembly in the .NET Framework 1.1 application.

