?
Solved

Current thread must be set to single thread apartment

Posted on 2007-04-11
2
Medium Priority
?
4,591 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 3

Accepted Solution

by:
JipFromParis earned 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
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.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

743 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