Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Runtime error for OpenFileDialog Class in .NET 2005

Runtime error for OpenFileDialog Class in .NET 2005

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++helpcsharpcom
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    priyank_ldce
    wrote on last edited by
    #1

    Hi all, I am transferring to .NET 2003 to .NET 2005 now. I have one application made in Visual C++.NET 2003. It is compiling fine in .NET 2005 but it gives one run time error at ShowDialog() function of OpenFileDialog Class object. Error is

    “An unhandled exception of type 'System.Threading.ThreadStateException' occurred in System.Windows.Forms.dll

    Additional information: 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.”

    Can I know what is wrong with this? And how can I solve this problem. Thanks in advance, Priyank

    M M S 3 Replies Last reply
    0
    • P priyank_ldce

      Hi all, I am transferring to .NET 2003 to .NET 2005 now. I have one application made in Visual C++.NET 2003. It is compiling fine in .NET 2005 but it gives one run time error at ShowDialog() function of OpenFileDialog Class object. Error is

      “An unhandled exception of type 'System.Threading.ThreadStateException' occurred in System.Windows.Forms.dll

      Additional information: 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.”

      Can I know what is wrong with this? And how can I solve this problem. Thanks in advance, Priyank

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      This should be posted on the Managed C++/CLI board. I'm not sure what threads have to do with using the OpenFileDialog, but the error message is pretty descriptive - it even states how to fix it. Which version of ShowDialog() are you using? Mark

      "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

      1 Reply Last reply
      0
      • P priyank_ldce

        Hi all, I am transferring to .NET 2003 to .NET 2005 now. I have one application made in Visual C++.NET 2003. It is compiling fine in .NET 2005 but it gives one run time error at ShowDialog() function of OpenFileDialog Class object. Error is

        “An unhandled exception of type 'System.Threading.ThreadStateException' occurred in System.Windows.Forms.dll

        Additional information: 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.”

        Can I know what is wrong with this? And how can I solve this problem. Thanks in advance, Priyank

        M Offline
        M Offline
        Michael Dunn
        wrote on last edited by
        #3

        "Ensure that your Main function has STAThreadAttribute marked on it." Have you tried this?

        --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ Dunder-Mifflin, this is Pam.

        S 1 Reply Last reply
        0
        • M Michael Dunn

          "Ensure that your Main function has STAThreadAttribute marked on it." Have you tried this?

          --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ Dunder-Mifflin, this is Pam.

          S Offline
          S Offline
          Stephen Hewitt
          wrote on last edited by
          #4

          Are you switching to the "dark side of the force"? ;)

          Steve

          1 Reply Last reply
          0
          • P priyank_ldce

            Hi all, I am transferring to .NET 2003 to .NET 2005 now. I have one application made in Visual C++.NET 2003. It is compiling fine in .NET 2005 but it gives one run time error at ShowDialog() function of OpenFileDialog Class object. Error is

            “An unhandled exception of type 'System.Threading.ThreadStateException' occurred in System.Windows.Forms.dll

            Additional information: 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.”

            Can I know what is wrong with this? And how can I solve this problem. Thanks in advance, Priyank

            S Offline
            S Offline
            Stephen Hewitt
            wrote on last edited by
            #5

            I think Mike's onto something here; the error message is describing exactly what's wrong. See here[^] for more details.

            Steve

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups