Click here to Skip to main content
15,878,959 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
{"
Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it.
"}


It happens when I initialize a runtime Combobox.

C#
this.cmbPlusPhysician.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest;
Posted
Comments
[no name] 26-Aug-14 9:59am    
Ensure that your Main function has STAThreadAttribute marked on it
KUMAR619 26-Aug-14 10:07am    
Yes Sir, [STAThread] is above main function.
What may be the problem prevailing
Rob Philpott 26-Aug-14 10:23am    
Are you using COM components? ActiveX?

You could try this (I doubt it will work but its worth a go, the apartment state will be set already)

Thread.CurrentThread.SetApartmentState(ApartmentState.STA);

[Edit] At the least, see what the value of the apartment state is on the GUI thread.
gggustafson 26-Aug-14 13:46pm    
I have found there to be a difference between

public static void Main ( string [ ] args )

and

[ STAThread ]
public void Main ( string [ ] args )

I use the former.
Sergey Alexandrovich Kryukov 26-Aug-14 16:44pm    
One cannot use non-static Main as entry point. The compiler will either say the entry point is not found, or some other function will be the entry point.

If [STAThread] is not added, STA will be assumed. OP maintains that [STAThread] is specified, but I doubt it (I remember this member for too long :-( ...).
The only other possibility would be that MTA is explicitly set in the thread running the code in question, as Ron Philpott shown (only the opposite, MTA), but I doubt it's the case...
I would rather believe that the problem is inadequately reported.

—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900