Solved

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

Posted on 2013-02-04
7
251 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 74

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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Converting C# Objects into JSON file 7 41
.Net application crashing 6 22
SQL best practice question 3 20
XML & .net 5 21
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…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

743 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

9 Experts available now in Live!

Get 1:1 Help Now