NullReferenceException - but where?!

G

Guest

Hi peeps,

I'm suddenly getting a very strange error on one of my websites. It seems to
be crashing within SaveViewState (?) but I can't tell if that the case, or if
there is something else going on.

The error occurs when I load a certain page with 2 lists, one shows a
collection of contacts, and the other looks at which of those contacts are
tied to a project. On load, I load the contacts list, and then loop through
the project contacts and copy the data from the other list. All contacts in
the project are still in the contacts list, so thats ok, but why am I getting
a viewstate crash?!

Here's the error...

Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

Source Error:

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.

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an
object.]
System.Web.UI.WebControls.ListItemCollection.SaveViewState() +102

System.Web.UI.WebControls.ListItemCollection.System.Web.UI.IStateManager.SaveViewState() +4
System.Web.UI.HtmlControls.HtmlSelect.SaveViewState() +39
System.Web.UI.Control.SaveViewStateRecursive() +59
System.Web.UI.Control.SaveViewStateRecursive() +160
System.Web.UI.Control.SaveViewStateRecursive() +160
System.Web.UI.Page.SaveAllState() +466
System

What's going on!?

Thanks,


Dan
 
W

Walter Wang [MSFT]

Hi Dan,

Glad to see you again in ASP.NET newsgroup! Have you seen my reply in your
post "getting the current page from inside a web control"? Please feel free
to reply there if there's anything I can help.

Regarding this post, I understand that you're seeing some
NullReferenceException and want to know how to debug it effectively.

From the stack trace, the exception is thrown from
ListItemCollection.SaveViewState, which is simply saving each ListItem into
ViewState.

If this exception can be reproduced on your develop machine, please use
following steps to debug it:

1. In Visual Studio 2005, click menu "Debug/Exceptions..."
2. Click button "Find", enter "System.NullReferenceException", click "OK"
3. When the exception if found in the list, check it, click "OK" to close
the exceptions dialog.
4. Start debugging your web site, when the exception is thrown, Visual
Studio will break at the code where the exception is thrown, since we don't
have the source code of System.Web.dll, we simply click the button "Show
Disassembly" when prompted.
5. Click on menu "Debug/Windows/Call Stack" to show the call stack, click
on menu "Debug/Windows/Locals" to show the local variables window;
6. In the call stack window, double click on the top most stack frame,
inspect the Locals window to view the variables; you should see "this" with
System.Web.UI.WebControls.ListItemCollection type, try to inspect its
state. I think some of its listItems might be null.


If this issue can be easily reproduced with a smaller web site; you can
send it to me and I will help to find the root cause. Thanks.


Sincerely,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 

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

Members online

No members online now.

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,113
Latest member
Vinay KumarNevatia
Top