Groups | Blog | Home
all groups > dotnet interop > august 2006 >

dotnet interop : Mind Boggling Behavior


Shea
8/30/2006 8:49:22 AM
[STAThread]
static void Main()
{
ApartmentState x =
Thread.CurrentThread.GetApartmentState();
MessageBox.Show(x.ToString());
// etc.
}

Brings up a most annoying dialog box with my current three least
favorite letters in the English lanuage:

MTA

The previously described behavior results after the project was
upgraded from VS 2003 to VS 2005 ... I looked through the
project/solution settings but can not find anything that would seem to
"override" the [STAThread] attribute. Trying to set the apartment state
to STA results in another exception.

I'm probably missing something stupid - anyone have any ideas?

Thanks.
Shea
8/30/2006 9:04:11 AM
Found another topic which addressed the issue:

http://groups.google.ca/group/microsoft.public.dotnet.framework.interop/browse_thread/thread/8b9dcdea483f8962/1bafd56c45fc9c9e?lnk=st&q=STAThread+ignored&rnum=1&hl=en#1bafd56c45fc9c9e

In short:

"Now I found the problem. It has nothing to do with the CoUnitialize().

I unchecked the "Enable the Visual Studio hosting process" for my
projekt an
everything is working fine. Thats the case for my old VS2003 projekt
which I
converted to VS2005.

For evaluation I added a new project (real VS2005 project) to my
solution
and paste in exactly the same main code as I had in my existing
project. If I
run this new application with "VS hosting process" enabled everything
working
fine too.

So there musst be a different handling of "converted" and "real" VS2005
projects. "

[quoted text, click to view]
AddThis Social Bookmark Button