First, I'll give you the background information. I have an MDI application that I've written in C#, .NET 2.0. The app's Main() is decorated with [STAThread]. There are three child windows that use a "report window" to display data in a WebBrowser control; let's call them Window 1, 2 and 3. I pass XML as a string from each of the three windows as a parameter to the constructor. That string is then transformed to HTML using an XslCompiledTransform object. When the report window is opened, it is being opened as a Dialog window.
If I open window 1 and request the report, everything works as expected. If I dismiss the dialog, open window 2 and request the report, again, everything works as expected. Window 3, same thing. Here is where the weirdness starts. If I open window 1, run the report, open either other window, run the report, then open window 1 again and run the report, I get an exception (ActiveX control '8856f961-340a-11d0-a96b-00c04fd705a2' cannot be instantiated because the current thread is not in a single-threaded apartment) in the Visual Studio-generated InitializeComponent() code implying that I have a threading model problem when it does the following: this.webBrowser = new System.Windows.Forms.WebBrowser();
How can this be? The main() function is clearly marked as [STAThread]. I even added "Thread.CurrentThread.SetApartmentState(ApartmentState.STA);" to the constructor before the InitializeComponent() call; no luck. The only controls on that window are the WebBrowser control and two standard buttons. To make things weirder, if I do an open/request on window 1, I can do an unlimited number of open/request actions on the other two windows. It's only when I go back to window 1 that the exception is thrown.
Can anyone shed any light at all on this subject? I've exhausted all of the Google queries I can think of.
Thanks in advance.