How can I debug a form calling an openFileDialog?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • franknagy
    New Member
    • Oct 2011
    • 27

    How can I debug a form calling an openFileDialog?

    Gentle Advisors,
    I have a form where a button selects an image and passes it on a control of this form and an other one.
    I wanted to debug the statements but I got an error message at the source line
    Code:
    if (openFileDialog1.ShowDialog() == DialogResult.OK)
    :

    "Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttrib ute marked on it. This exception is only raised if a debugger is attached to the process."


    What have I to do? What have I to insert in Main?

    Regards
    Frank
  • snehasismishra1
    New Member
    • Aug 2011
    • 18

    #2
    Hi,

    Add the STAThreadAttrib ute attribute on the Main method.

    C#
    Code:
    [STAThread]
    static void Main(string[] args)
    
    {
    
    }
    Thanks,
    Snehasis

    Comment

    • franknagy
      New Member
      • Oct 2011
      • 27

      #3
      Thanks,
      Snehasis.
      After insertion of the magic
      Code:
      [STAThread]
      line the debugger survived the OpenFileDialog call.

      Please explain me what are the other effects of this magic word.
      Where can I find a documentation of magic words to be inserted in square brackets of C# source files?

      Regards
      Frank

      Comment

      • snehasismishra1
        New Member
        • Aug 2011
        • 18

        #4
        Hi Frank,

        Sorry for the late reply. I have also not much idea :(. I read from net. you can check the below link.



        Thanks,
        Snehasis

        Comment

        Working...