Click here to Skip to main content
15,889,034 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hi to all,
I want to open SaveFileDialog Box. But am getting the Error :

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. This exception is only raised if a debugger is attached to the process.

I am Developing the project using WPF and VS2010. Developed UI Using WPF. At the manager Layer I tried to Open SaveFileDialog Box.
I tried To set the [STAThreadAttribute] and [STAThread] attributes but I was not able to implement that can any one help me please.
Posted
Updated 30-Nov-16 5:11am
v2
Comments
Khaniya 9-Oct-10 2:57am    
where you have set [STAThreadAttribute] and [STAThread]
?????

I hav face the same probleme , to call a COM object

what i did , is make a thread with single thread apartment ,

and do what i have to do
Thread staThread = new Thread(new ThreadStart (myMethod));
staThread.ApartmentState = ApartmentState.STA;
staThread.Start();

public static void myMethod()
{
    //Call COM Object
}
 
Share this answer
 
Comments
Dalek Dave 13-Oct-10 5:53am    
Good Call
C#
// Do this
class Program
{
    [STAThreadAttribute]
    static void Main(string[] args)
    {
    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900