Make VB6 COM Components Work With ASP.NET
Avoid big performance hits — or outright failure — by marking your ASP.NET pages ASP-compatible.
October 30, 2009
Hot Tip
LANGUAGES:All .NET Languages
TECHNOLOGIES:COM Components | @ Page Directives
Make VB6 COM Components Work With ASP.NET
Avoid big performance hits - or outright failure - bymarking your ASP.NET pages ASP-compatible.
By Jeff Prosise
If your ASP.NET application uses COM components written inVisual Basic 6.0, be sure to mark the pages that use them as ASP-compatiblewith an @ Page directive:
<%@ Page AspCompat="true" %>
Why? Some ASP.NET pages that use ASP COM components don'trun without this directive. Others do, but they will incur a measurable (andsometimes dramatic) performance hit.
Here's the reason for the performance hit. By default,threads that process ASP.NET requests reside in a COM multithreaded apartment(MTA). COM components written in VB6 - and COM components written in anylanguage (including C++) that are registered asThreadingModel="Apartment" or that have no registered ThreadingModelvalue - run in COM single-threaded apartments (STAs). When threads running in anMTA call objects in STAs, those calls must be marshaled across apartmentboundaries. They incur thread switches as they enter an STA.AspCompat="true" forces ASP.NET threads into STAs, allowing thosethreads to call STA-based COM objects without marshaling or thread switches.
As a corollary, you should not use AspCompat="true" with COMcomponents registered as ThreadingModel="Free" orThreadingModel="Both". ASP COM components of this type are relativelyrare, but they do exist. For more information and an in-depth analysis of themeaning and implications of AspCompat="true", read my "Ask the Pro"column in the March 2003 issue of asp.netPRO.
Jeff Prosise is author of several books, including Programming Microsoft .NET (Microsoft Press).He also is a co-founder of Wintellect (http://www.wintellect.com),a software consulting and education firm that specializes in .NET.
Read more about:
MicrosoftAbout the Author
You May Also Like