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#
  4. COM Object

COM Object

Scheduled Pinned Locked Moved C#
comasp-netquestion
6 Posts 3 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.
  • F Offline
    F Offline
    FlamTaps
    wrote on last edited by
    #1

    Hello, I am trying to instantiate a COM object. However, I am having some problems with threading. When I try to instantiate it without any threading statements, as follows: public static void Main(String[] args) { Application.Run(new SetupCreator()); } public SetupCreator() { ESRI.MapObjects2.Core.AxMap map1 = new ESRI.MapObjects2.Core.AxMap(); /*....*/ this.Controls.Add(map1); } I get the exception: "Could not instantiate ActiveX control '9bd6a64b-ce75-11d1-af04-204c4f4f5020' because the current thread is not in a single-threaded apartment." So, I did some research, and added the line to just before main. With that there, I get "There is no source code available for the current location". I found another approach, which adds the line: Thread.CurrentThread.SetApartmentState(ApartmentState.STA); and getting rid of the STAThread line. Now, with this in place, I get "Failed to set the specified COM apartment state." So, I am a little lost as to what to do. Any suggestions?

    M 1 Reply Last reply
    0
    • F FlamTaps

      Hello, I am trying to instantiate a COM object. However, I am having some problems with threading. When I try to instantiate it without any threading statements, as follows: public static void Main(String[] args) { Application.Run(new SetupCreator()); } public SetupCreator() { ESRI.MapObjects2.Core.AxMap map1 = new ESRI.MapObjects2.Core.AxMap(); /*....*/ this.Controls.Add(map1); } I get the exception: "Could not instantiate ActiveX control '9bd6a64b-ce75-11d1-af04-204c4f4f5020' because the current thread is not in a single-threaded apartment." So, I did some research, and added the line to just before main. With that there, I get "There is no source code available for the current location". I found another approach, which adds the line: Thread.CurrentThread.SetApartmentState(ApartmentState.STA); and getting rid of the STAThread line. Now, with this in place, I get "Failed to set the specified COM apartment state." So, I am a little lost as to what to do. Any suggestions?

      M Offline
      M Offline
      MilesAhead
      wrote on last edited by
      #2

      Have you tried importing it into the Toolbox and dropping it on the main form of a test application? Perhaps if that works you can look at the Form Designer generated code for clues.

      F 1 Reply Last reply
      0
      • M MilesAhead

        Have you tried importing it into the Toolbox and dropping it on the main form of a test application? Perhaps if that works you can look at the Form Designer generated code for clues.

        F Offline
        F Offline
        FlamTaps
        wrote on last edited by
        #3

        Unfortunatly that did not work. I still need help on this problem. Any other suggestions?

        A 1 Reply Last reply
        0
        • F FlamTaps

          Unfortunatly that did not work. I still need help on this problem. Any other suggestions?

          A Offline
          A Offline
          Anonymous
          wrote on last edited by
          #4

          "that did not work" is kinda' vague. Could you import the control? Could you drop it on the form? Did it give an error msg?

          F 1 Reply Last reply
          0
          • A Anonymous

            "that did not work" is kinda' vague. Could you import the control? Could you drop it on the form? Did it give an error msg?

            F Offline
            F Offline
            FlamTaps
            wrote on last edited by
            #5

            Your right, I appologize. I did import the control, the reference was there. I I drug the control onto the form and looked at the Form Designer generated code. There was very little in difference. Then, I executed the app, and I got the same senario ("There is no source code available for the current location") since the generated code added the "[STAThread]" line.

            M 1 Reply Last reply
            0
            • F FlamTaps

              Your right, I appologize. I did import the control, the reference was there. I I drug the control onto the form and looked at the Form Designer generated code. There was very little in difference. Then, I executed the app, and I got the same senario ("There is no source code available for the current location") since the generated code added the "[STAThread]" line.

              M Offline
              M Offline
              MilesAhead
              wrote on last edited by
              #6

              I don't think I've run across anything like that. Do you know if the ActiveX was implemented in VB by any chance? I ask because I've seen some references to VB ActiveX or COM objects not being marked with the "creatable" attribute on some of the Delphi ngs. Other than that I'm afraid I don't have any idea. Perhaps google on the GUID or CLSID and see if this control shows up in bug reports is all I can suggest. Sorry I couldn't be more help.

              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