Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2013-02-04
7
Medium Priority
?
265 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 501 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:Meir Rivkin
Meir Rivkin earned 501 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
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
LVL 10

Assisted Solution

by:Monica P
Monica P earned 498 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 2

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 2

Author Closing Comment

by:niceoneishere
ID: 38958200
Thanks
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Loops Section Overview
Suggested Courses

824 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