Solved

What does this error mean in asp.net 2.0 and C#

Posted on 2013-02-04
7
252 Views
Last Modified: 2013-03-06
My site is built in ASP.NET 2.0 and C# using SQL 2005 Database. I am writing all the error to my db in table called Exceptions.

Lately I have noticed that on my Products page, this error keeps getting written to the Exception table a lot. And I am not able to replicate it, if I want to check it out.

 System.NullReferenceException: Object reference not set to an instance of an object. at MySite.products.showItems(Int32 pageIndex) in c:\Websites\gn4f4ada\browse\products.aspx.cs:line 547 at MySite.products.Page_Load(Object sender, EventArgs e) in c:\Websites\gn4f4ada\browse\products.aspx.cs:line 68

Open in new window


in products.aspx.cs line 68 is

   try
            {
                if (!this.IsPostBack)
                {
                    this.CategoryId = Convert.ToInt32(Request[REQ_CATEGORY_ID]);
                    this.showItems(this.PageIndex);  // THIS IS LINE 68
                }
            }
            catch (Exception ex)
            {
                this.HandlePageError(ex);
            }

Open in new window


and line 547

     private void showItems(int pageIndex)
        {
            Category view;
            if (SelectedSize > -1)
            {
                view = this.CurrentCategory.GetView(
                    (SizeType)SelectedSize,
                    (Gender)SelectedGender);
            }
            else
            {
                if (SelectedGender > 0)
                {
                    view = this.CurrentCategory.GetView((Gender)SelectedGender);
                }
                else
                {
                    view = this.CurrentCategory;
                }
            }

            this.pager.SetPagingLabels(view.ItemCount);  // THIS IS LINE 547

            if (this.ViewMode == MySitePage.ViewMode.Paged)
            {
                this.rProducts.DataSource = view.GetPage(pageIndex, this.pager.PageSize);
            }
            else
            {
                this.rProducts.DataSource = view.Items;
            }
            this.rProducts.DataBind();
        }

Open in new window


any advice or suggestions are appreciated
0
Comment
Question by:niceoneishere
7 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 38851439
Is either pager or view null at the point the exception is raised? Have you tried stepping through your code?
0
 
LVL 5

Accepted Solution

by:
Rainverse earned 167 total points
ID: 38851450
It means view.ItemCount is Null at that point. Possibly because it's before postback?

-MJC
0
 
LVL 42

Assisted Solution

by:sedgwick
sedgwick earned 167 total points
ID: 38851451
first of all since you know this could happen, check view variable before calling this.pager.SetPagingLabels:
if(view == null){
throw new Exception("Nullable view.....");
}

this.pager.SetPagingLabels(view.ItemCount);  

Open in new window


in the exception you throw here, add additional data which will tell you what might be the problem (like SelectedSize, SelectedGender etc).
i'd go and create custom exception but its not really necessary for this case.

i assume its something with this.CurrentCategory.GetView() which might returns null.
if you knew what is the value of SelectedSize and SelectedGender , you could have known which case is about.

so i'd start with that.
post here if you have any updates.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 10

Assisted Solution

by:Monica P
Monica P earned 166 total points
ID: 38853857
this.CategoryId = Convert.ToInt32(Request[REQ_CATEGORY_ID]);

check  if Request[REQ_CATEGORY_ID]) contains value..

and then convert into int32..
sometime This may also produce error....

if not request(rea_category_id) =nothing then
  this.CategoryId = Convert.ToInt32(Request[REQ_CATEGORY_ID]);
endif
0
 
LVL 1

Author Comment

by:niceoneishere
ID: 38861632
The problem is I am not able to replicate it. It only shows up in the Exception Table
0
 
LVL 5

Expert Comment

by:Rainverse
ID: 38861654
That's because you're doing error handling.
0
 
LVL 1

Author Closing Comment

by:niceoneishere
ID: 38958200
Thanks
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now