Solved

Current thread must be set to single thread apartment

Posted on 2007-04-11
2
4,533 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

706 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now