When to set AspCompat

Wednesday, September 20, 2006

If we interop with a COM component from ASP.NET, we might need to use AspCompat="true" in the @ Page directive. The question is: when do we need AspCompat?

The answer is that we need AspCompat if the COM component has to run on a thread initialized into a single threaded apartment (STA). This begs the question: how do we know if a component needs to run in an STA?

One answer is to dig into the HKEY_CLASSES_ROOT section of the registry and find the component by CLSID (or by ProgID, which can give us the CLSID). Inside will be an InprocServer32 key, which holds a ThreadingModel value.

We could also find this value using the OLE/COM Object Viewer. Locate the component on the left, and look for the ThreadingModel setting on the right.

If the ThreadingModel value is "Apartment", we need to use AspCompat="true" (and look for ways to get rid of the component). If the value is "Free", "Neutral", or "Both", then we don't need AspCompat.

This post was brought to you by the Ministry of Boring Trivia, headquartered in a bar in the airport of Savannah, Georgia.


Comments
vikram Thursday, September 21, 2006
Now I fully understood why we needed AspCompat
Thanks
Comments are now closed.
by K. Scott Allen K.Scott Allen
My Pluralsight Courses
The Podcast!