VS.NET 2005 Designer - null reference exception

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form "form1" that I can open in vs.net 2005 designer. Now I also
have "form2" which is derived from form1. I can not open this "form2" in
designer view which shows null reference exception on design view.

On call stack, it is showing that designer is trying to call form1.shown
method which has one reference which is not set yet.

How come I can open "form1" in design view but can not "form2"?

Any idea how to solve this problem?
 
In Form2's constructor, do you call the Base (Form1) constructor? In VB
it's Mybase.New()
 
I have a form "form1" that I can open in vs.net 2005 designer. Now I also
have "form2" which is derived from form1. I can not open this "form2" in
designer view which shows null reference exception on design view.

On call stack, it is showing that designer is trying to call form1.shown
method which has one reference which is not set yet.

How come I can open "form1" in design view but can not "form2"?

Any idea how to solve this problem?

In order to show a form in the IDE, the IDE needs to instantiate the
parent class of the form, then it manually runs the
InitializeComponent method of the form to get the child objects
created. That apparently works fine for form1.

In order to show form2, the IDE needs to instantiate a form1 object,
and that apparently fails due to the reference which is not set. One
work-around is in form1 to check the DesignMode property and if True
avoid accessing the property that you know is not set. Or perhaps if
DesignMode is True you could set the reference to something safe that
would let the form instantiate.
 
Thank you Jason. Your solution worked.
--
Thanks,
Mahesh



Jason Allred said:
In Form2's constructor, do you call the Base (Form1) constructor? In VB
it's Mybase.New()
 
Back
Top