0x800A0062 when using COM Interop on ASP.NET

Like many exceptions related to COM Interop, the exception COMException(0X800A0062): Exception from HRESULT: 0X800A0062 can have many causes. The information is out there on the web, and I was eventually able to track down a solution for my application. However, there is a fair trail of bread crumbs one must follow from searching on the original error to finding a solution for this problem in ASP.NET. To spare other developers the hassle, I have posted my solution here.

Generally, this error results from an attempt to access a STA (single-threaded apartment) COM component from a context with a different threading model. VB6 DLLs are generally STA COM components. ASP.NET pages, by default, do not run in a single-threaded apartment. As a result, this error can easily occur if you try to access a VB6 component from ASP.NET.

The easiest solution is to set the ASP.NET page to run in STA mode. To do this, add AspCompat=”true” to the <%@ Page … %> directive on the page that uses the COM component. This flag is set on a page-by-page basis.

Microsoft has a page about this, but it is hard to find because it does not mention the error that occurs if you don’t include the AspCompat flag in your page directive.

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s