NullReference Exception - Upgrade blues!

  • Thread starter Thread starter Paul Cheetham
  • Start date Start date
P

Paul Cheetham

Hi,

I have moved a fairly large project from VS2003 to VS2005, and now
trying to get it running.

It now compiles OK after minimal changes, but I am now getting a
NullReference Exception on the following line:

if (_Screen.ActiveForm == this)


Both _Screen.ActiveForm and the current form are descendants of
System.Windows.Forms.Form.
This worked perfectly well in VS2003, and I can't see why it won't work
here. _Screen.ActiveForm is null, but I am not trying to access any of
it's members, just check if it is the current form.


Can anybody point me in the right direction?


Thanks.

Paul Cheetham
 
Paul Cheetham said:
I have moved a fairly large project from VS2003 to VS2005, and now
trying to get it running.

It now compiles OK after minimal changes, but I am now getting a
NullReference Exception on the following line:

if (_Screen.ActiveForm == this)

Both _Screen.ActiveForm and the current form are descendants of
System.Windows.Forms.Form.
This worked perfectly well in VS2003, and I can't see why it won't work
here. _Screen.ActiveForm is null, but I am not trying to access any of
it's members, just check if it is the current form.

Is _Screen itself null by any chance?

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
 
Hi Jon,

_Screen itself is null, so that explains that, It's not getting
initialised as it should.
The problem seems to be that objects are being created in a different
order than they were in VS2003, meaning that not everything is being
initialised properly.


Thanks.

Paul
 
Paul Cheetham said:
_Screen itself is null, so that explains that, It's not getting
initialised as it should.
The problem seems to be that objects are being created in a different
order than they were in VS2003, meaning that not everything is being
initialised properly.

Again, could you post the code which demonstrates the problem? Chances
are it's easy to fix.
 
Hi,

Paul Cheetham said:
Hi Jon,

_Screen itself is null, so that explains that, It's not getting
initialised as it should.
The problem seems to be that objects are being created in a different
order than they were in VS2003, meaning that not everything is being
initialised properly.

How are you assigning it? or where
 
Back
Top