Object reference not set to an instance of an object

G

Guest

Hi,

I built a C# web application, all things are ok when i test locally. I
deploy it to a remote server. I set <customErrors mode="Off" /> in
web.config.

One of the aspx page has the problem "Object reference not set to an
instance of an object". An unhandled exception was generated during the
execution of the current web request. Information regarding the origin and
location of the exception can be identified using the exception stack trace
below.

[NullReferenceException: Object reference not set to an instance of an
object.]
GuiMingWeb.Account.buy.Page_Load(Object sender, EventArgs e) in
e:\webapplication\account.aspx.cs:89
System.Web.UI.Control.OnLoad(EventArgs e) +63
System.Web.UI.Control.LoadRecursive() +31
System.Web.UI.Page.ProcessRequestMain() +731

Since it has no build and runtime error when I test it at localhost, the
page has that error only when I see it on remote server.

I do not know how to debug it kind of error. All other aspx pages do not
have that problem.

Any suggestion?

Thanks for any help.
 
M

Matt

Tom said:
Hi,

I built a C# web application, all things are ok when i test locally. I
deploy it to a remote server. I set <customErrors mode="Off" /> in
web.config.

One of the aspx page has the problem "Object reference not set to an
instance of an object". An unhandled exception was generated during the
execution of the current web request. Information regarding the origin and
location of the exception can be identified using the exception stack trace
below.

[NullReferenceException: Object reference not set to an instance of an
object.]
GuiMingWeb.Account.buy.Page_Load(Object sender, EventArgs e) in
e:\webapplication\account.aspx.cs:89
System.Web.UI.Control.OnLoad(EventArgs e) +63
System.Web.UI.Control.LoadRecursive() +31
System.Web.UI.Page.ProcessRequestMain() +731

Since it has no build and runtime error when I test it at localhost, the
page has that error only when I see it on remote server.

I do not know how to debug it kind of error. All other aspx pages do not
have that problem.

Any suggestion?

Its hard to say without seeing the code. Can you post the Page_Load
handler? It looks like it is telling you that the error is on line 89,
and is caused by referring to an object that is null.

Matt
 
N

Nick Malik [Microsoft]

Hi Tom,

If it only happens on the remote server and not on localhost, look for
situations where a call is returning no object instead of an expected
object, especially if permissions play a role in creating the object. For
example: if you open a file and create a text reader at the same time... if
you don't the right to open the file, the text reader will not be created.
Any reference to the text reader would cause the error indicated.

Consider placing a try-catch block in the code around the lines referenced.
That should help you narrow down what is going on and to catch it correctly.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
 
G

Guest

Thank you for both of your suggestion. I fixed the bug after adding the try
catch block.

The error occurred because the data binding with DB returns null value.

Thanks for help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top