N
Nick Valeontis
I was writing a C# program this week. The program works okay in my pc (in
both debug and release builds) but realized that it would not work to other
pcs. It simply would close after displaying an "This program has encountered
an error etc etc etc.." popup.
I added some try, catch blocks and found that the error message was: "Object
reference not set to an instance bla bla". After spending some time to
locate the line that causes the problem, I again realized that the code was
generated by the designer! And .. that I have no idea at all of what is
really happening. The lines that cause the problem are:
this.Resize += new System.EventHandler(this.frmGraphics_Resize);
this.ResumeLayout(false);
frmGraphics function is:
private void frmGraphics_Resize(object sender, EventArgs e) {
UpdateControls();
}
UpdateControls is self explanatory. It checks if text in various controls of
the form should be updated.
Can anyone tell me why this code generates this error?
Note that if I change the lines
this.Resize += new System.EventHandler(this.frmGraphics_Resize);
this.ResumeLayout(false);
to
this.ResumeLayout(false);
this.Resize += new System.EventHandler(this.frmGraphics_Resize);
Then it will work okay.
So ... what is the catch??? :/ Does anyone have any idea?
-nick
both debug and release builds) but realized that it would not work to other
pcs. It simply would close after displaying an "This program has encountered
an error etc etc etc.." popup.
I added some try, catch blocks and found that the error message was: "Object
reference not set to an instance bla bla". After spending some time to
locate the line that causes the problem, I again realized that the code was
generated by the designer! And .. that I have no idea at all of what is
really happening. The lines that cause the problem are:
this.Resize += new System.EventHandler(this.frmGraphics_Resize);
this.ResumeLayout(false);
frmGraphics function is:
private void frmGraphics_Resize(object sender, EventArgs e) {
UpdateControls();
}
UpdateControls is self explanatory. It checks if text in various controls of
the form should be updated.
Can anyone tell me why this code generates this error?
Note that if I change the lines
this.Resize += new System.EventHandler(this.frmGraphics_Resize);
this.ResumeLayout(false);
to
this.ResumeLayout(false);
this.Resize += new System.EventHandler(this.frmGraphics_Resize);
Then it will work okay.
So ... what is the catch??? :/ Does anyone have any idea?
-nick