Make VB6 COM Components Work With ASP.NET

Avoid big performance hits — or outright failure — by marking your ASP.NET pages ASP-compatible.

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 - by marking your ASP.NET pages ASP-compatible.

 

By Jeff Prosise

 

If your ASP.NET application uses COM components written in Visual Basic 6.0, be sure to mark the pages that use them as ASP-compatible with an @ Page directive:

<%@ Page AspCompat="true" %>

 

Why? Some ASP.NET pages that use ASP COM components don't run without this directive. Others do, but they will incur a measurable (and sometimes 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 any language (including C++) that are registered as ThreadingModel="Apartment" or that have no registered ThreadingModel value - run in COM single-threaded apartments (STAs). When threads running in an MTA call objects in STAs, those calls must be marshaled across apartment boundaries. They incur thread switches as they enter an STA. AspCompat="true" forces ASP.NET threads into STAs, allowing those threads to call STA-based COM objects without marshaling or thread switches.

 

As a corollary, you should not use AspCompat="true" with COM components registered as ThreadingModel="Free" or ThreadingModel="Both". ASP COM components of this type are relatively rare, but they do exist. For more information and an in-depth analysis of the meaning 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.

 

 

 

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish