Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2013-02-04
7
Medium Priority
?
259 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 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:sedgwick
sedgwick 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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 …
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

722 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