STAThread missing, but it is there

It might be that you are facing the following problem reported on Connect1:

.vshost.exe forces wrong threading model used when debugging a .exe if a .dll of the same name exists in same bin directory

According to that issue it happens that the hosting process of Visual Studio, i.e. the myprogram.vshost.exe enforces the wrong apartment state when you have both a myprogram.exe and a myprogram.dll file in your output folder.

The problem might be specific to some older version of Visual Studio (2005), and I haven’t been able to reproduce it using VS 2010.

The obvious workaround would be to change the name of the dll or to move the dll to another folder.

The situation might have come up because you changed the output type of your project from class libary to Windows application.

1It is unclear whether this problem is confirmed by Microsoft or not, it just says that the problem is outside the responsibility of the VS product team.

Leave a Comment