Click here to Skip to main content
12,896,953 members (52,037 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# WPF C#4.0
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 5-Oct-10 20:17pm
Updated 30-Nov-16 5:11am
Khaniya 9-Oct-10 2:57am
where you have set [STAThreadAttribute] and [STAThread]
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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;
public static void myMethod()
    //Call COM Object
Dalek Dave 13-Oct-10 5:53am
Good Call
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

// Do this
class Program
    static void Main(string[] args)

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

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170424.1 | Last Updated 30 Nov 2016
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100