COM Object
-
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? -
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?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.
-
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.
-
Unfortunatly that did not work. I still need help on this problem. Any other suggestions?
-
"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?
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.
-
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.
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.