Solved

Current thread must be set to single thread apartment

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

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

Suggested Solutions

Title # Comments Views Activity
how to remove duplicate code from my project 5 49
need to convert function to c# 5 45
C# Formatting DateTime String Value 5 52
ComboBox to String Not Working 5 19
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

733 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