Solved

Current thread must be set to single thread apartment

Posted on 2007-04-11
2
4,556 Views
Last Modified: 2011-10-03
Hello

I converted a project to .net 2.0 from 1.1 using VS 2005.

When i'm running the compiled version, application is throwing this error message -

"DragDrop registration did not succeed. ---> System.Threading.ThreadStateException: 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."

I checked and the Main() function is marked with [STAThread] attribute.

Really not sure why this error is happening. Any help?

Thanks!

0
Comment
Question by:praveenuni
2 Comments
 
LVL 3

Accepted Solution

by:
JipFromParis earned 500 total points
ID: 18889676
It's more than likely you are creating additional threads apart from the main one. In .Net 2.0, new threads are created as MTA threads, albeit you explicitly invoke the SetApartmentState method on the thread, prior to starting it. The error you encounter may occur if drag/drop operation is handled by a thread in an MT apartment. Assuming you are running the application under Visual Studio and make the debugger break when the exception occurs, you should be able to discover the apartment style of the faulting thread using the VS 2005 Debug Command window and issuing the following command :

System.Threading.Thread.CurrentThread.GetApartmentState()
0
 

Author Comment

by:praveenuni
ID: 18899933
Thanks for the reply. I figured that my debug folder contained some old dlls which I had to remove and rebuild the solution again. This solved the problem.

Thanks again!
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question