Solved

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

Posted on 2013-02-04
7
256 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
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.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

734 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