user867661
user867661

Reputation: 1

Object reference not set to an instance of an object

I'm sorry if this is a really simple one but it's really confusing me.
I'm getting:

NullReferenceException was unhandled by user code : Object reference not set to an instance of an object.

When I run the following code:

a.Forms.Add(AppraisalForm.CreateNew(int.Parse(Session["AppID"].ToString()), option, 
    owner, webStatics.AuditUser(Session)))

I've used a breakpoint and is shows that:

Session["AppID"] is 14
Option is HOY
Owner is ETJ
AuditUser(Session) is [CBX]

I'm not sure what other information is needed but would be greatful if someone could help me out.

Upvotes: 0

Views: 367

Answers (2)

Paul Williams
Paul Williams

Reputation: 17020

Look at the values of a, a.Forms, AppraisalForm (if this is not a class), the return value of AppraisalForm.CreateNew, and the value of webStatics. Something in there is null. It would help to split this statement apart into multiple statements so you can see which line is causing the error.

Upvotes: 0

John Kraft
John Kraft

Reputation: 6840

Is the CreateNew returning null? Is a null? The easiest way to find it is to break each element out and assign it to it's own variable. That will tell you which piece is failing.

This problem is precisely why you should never write code like this.

Upvotes: 1

Related Questions