473,396 Members | 1,998 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

NullReferenceException - but where?!

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.SaveV iewState() +102

System.Web.UI.WebControls.ListItemCollection.Syste m.Web.UI.IStateManager.SaveViewState() +4
System.Web.UI.HtmlControls.HtmlSelect.SaveViewStat e() +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
Nov 28 '06 #1
1 1659
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 (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.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/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Nov 28 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Terrence | last post by:
I am doing some of the C# walkthroughs to transition from VB to C#. When I try to execute static void Main() { Aplication.Run(new Form1()) } I raise a 'System.NullReferenceException" in...
5
by: TT (Tom Tempelaere) | last post by:
Hi, Once in a while my application throws an NullReferenceException at startup, however it appears to be occurring in an unknown module. If I debug it and ask to 'break', then there is no source...
0
by: muralidharan | last post by:
WebForm1.aspx Code: <%@ Register TagPrefix="ComponentArt" Namespace="ComponentArt.Web.UI" Assembly="ComponentArt.Web.UI" %> <ComponentArt:TreeView id="TreeView1" Height="520"...
2
by: Janet Heflin | last post by:
Very new in the C# world so give me a break here. I have created two web forms, one passes information to the other and brings up the data based on the passed field. When I do the updateRow I get...
5
by: AAguiar | last post by:
I have an asp.net project where the code behind the aspx page calls a c# class which makes calls to a managed static C++ class. The C# class works fine when the asp net worker process starts, when...
2
by: sxiao | last post by:
Hi, there I got a NullReferenceException when there are more than one users trying to open the same page at the same time. The senerio is: Two users logged into the web application using the...
9
by: Xero | last post by:
could anybody describes a scenario where this error will occur? i have visited the page about the NullReferenceException in msdn library but i still have no idea what it is about. thanks. ...
1
by: Craig | last post by:
This is killing me, I've been trying to figure this out for 2 days. When I click on the linkbutton, it executes the GetData(int) method to set the DataSource. The FAILURE is when it tries to...
1
by: paul.hine | last post by:
Hello, I maintain an application that pulls data from a web service and writes it to an Excel sheet. Originally, the app used OleDb to write the Excel. Exports ran fine except that some text...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.