), included with the .NET Framework SDK, converts standard COM components in .dll files to equivalent .NET Framework assemblies by building managed wrappers around the components. The converted components can be early bound to managed code for greatly increased performance. For more information about Tlbimp.exe, see Exposing COM Components to the .NET Framework. For information about converting COM components to managed code, see Building COM Components for Interoperability.
After the COM component is converted to a .NET Framework assembly, you can import it into an ASP.NET page by placing a directive at the top of the page. For example, the following directive imports the namespace
MyNewNamespace, which was created by Tlbimp.exe.
The assembly file generated by Tlbimp.exe must be placed in the ASP.NET application's Bin directory. The original COM component file must be registered for the directory in which it resides.
When using single-threaded apartment (STA) COM components, such as components developed using Visual Basic, from an ASP.NET page, you must include the compatibility attribute AspCompat=true in an <%@ Page > tag on the ASP.NET page, as shown in the following code example.
The AspCompat attribute forces the page to execute in STA mode. The runtime throws an exception if the compatibility tag is omitted and an STA component is referenced on the page. If you convert the STA component to an assembly using Tlbimp.exe, the runtime does not detect that the component uses the STA model and does not throw an exception, but your application can suffer from poor performance.
For example, the following member declaration creates the component at construction time.
<%@ Page ' The components is created at construction time. Dim comObj As MyComObject = New MyComObject() Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) ' The object is first used here. comObj.DoSomething() End Sub </script> <html xmlns="" > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> </div> </form> </body> </html>
Instead, use code like the following.
<%@ Page ' The component is created and used after the code is running ' on the STA thread pool. Dim comObj As MyComObject = New MyComObject() comObj.DoSomething() </script> <html xmlns="" > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> </div> </form> </body> </html>
64-Bit Components
On a 64-bit version of Microsoft Windows, it is possible to run 32-bit applications using the WOW64 emulator. However, processes can only be 32-bit or 64-bit. You cannot have a process that runs both.
Internet Information Services (IIS) runs as a 64-bit application on 64-bit versions of Windows. The process type of a COM component must match the IIS worker process type. It is possible to run 32-bit components on the 64-bit version of IIS using one of the following solutions:
Configure the COM component as a COM+ application so that it runs in Dllhost.exe.
Configure IIS to run 32-bit applications. This option affects all applications on the IIS server. For more information, see Appendix D: Running 32-bit Applications on 64-bit Windows (IIS 6.0) in the IIS Deployment Guide.
It is recommended that you convert your components to 64-bit. In the case of Visual Basic components, this is not possible because there is no 64-bit version of the Visual Basic compiler.