InitializeComponent not called

  • Thread starter Thread starter muser8
  • Start date Start date
M

muser8

I've encountered a very bizarre situation: a form's Initialize
Component is not called and excution doesn't reach the code
immediately following the call to initialize component. So in the
following code sample the fist message box appears but the second does
not. A few quick facts:
- The form in question is being created by a parent form.
- No exceptions are thrown.
- If a MessageBox.Show is added to InitializeComponent,
that message box does not get displayed.

Here is the code fragement.

public Preview(DataSet dataSet, SomeObject someObject) {
MessageBox.Show("1");
this.InitializeComponent();
MessageBox.Show("2");
}

Any ideas would be very much appreciated.

Thanks,
Sean
 
Sean,

My guess is that an exception is actually being thrown, and you are not
catching it. That would explain why the first message box shows up, but not
the second.

However, you never see anything because most likely, you are creating
this component in the event handler for the form, and if there is an
exception, it gets swallowed.

I would put a try/catch block around the call to InitializeComponent,
and in the catch, if there is an exception, show the details of it in a
messagebox. I'd be willing to say you get something.

Hope this helps.
 
Back
Top