When to set AspCompat

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.

posted on Wednesday, September 20, 2006 4:44 PM by scott

Comments

Wednesday, September 20, 2006 9:19 PM by Christopher Steen

# Link Listing - September 20, 2006

Creating Validator Controls for the CheckBox and CheckBoxList [Via: ] Free MOSS 2007 Developer and Infrastructure...
Thursday, September 21, 2006 9:25 AM by vikram

# re: When to set AspCompat

Now I fully understood why we needed AspCompat
Thanks