I have an intermittent prob开发者_如何转开发lem where I cannot create an instance of the System.Windows.Forms.Form class in my C# library. I log exceptions in my program, but unfortunately nothing was recorded for this problem. It might not be relevant, but my library, called via COM (i.e. there is no Main method).
So I threw a test exception, and it was caught and logged successfully -- so I'm thinking that maybe something screwy is going on in the message loop?
Update 1
The Form is created using the following code in a Thread
which has ApartmentState.STA
set.
someForm = new Form();
someForm.Visible = false;
someForm.Text = "Hello world!";
It's just a guess, since you've provided no code and little context, but might you be missing the STAThread
attribute on your entry point method (Main
)? This is necessary for WinForms apps that make use of COM.
精彩评论