Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Current thread must be set to single thread apartment

Posted on 2007-04-11
2
Medium Priority
?
4,613 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

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.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

636 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