0
Reply

COM Object

CWOWeb

CWOWeb

Jul 9 2004 1:35 PM
3k
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 [STAThread 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?