Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
List<int> processedList = new List<int>();
            processedList = (List<int>) Session["processedUsers"];


I am getting argument null reference exception here????
XML
if(processedList.Count != 0)
{
  Boolean exists =  processedList.Contains(i);
    if (!exists)
    {
    }



I am getting Null reference exception even

Boolean exists = processedList.Exists(element => element ==i)

The session state list can be empty. Still I have run this test.
Please advise.
Posted
Updated 19-Oct-10 23:27pm
v4

You overwrite your processedList instance with a value from Session. So if there is no list instance in the session, you will get this exception.

So you probably don't have correctly initialized Session["processedUsers"] and thus you have exception.
 
Share this answer
 
Put simply,
C#
List<int> processedList = new List<int>();

Creates processedList and assignes a new, empty list to it.
processedList = (List<int>) Session["processedUsers"];

Replaces the empty list with whatever the cast returns.
if(processedList.Count != 0)
Uses the list contained in processedList to check the number of entries.

So if Session["processedUSers"] does not return a list then:
if it returns a non-list item it will throw a "cannot convert" exception.
if it returns a null, processedUsers will become null, and the empty list you assigned will be discarded.

If processedUsers is null, then attempting to access any element, even the items count, will give a null reference exception.

So: Check what Session["processedUSers"] is returning, and make sure that processedItems is a valid list before you try and use3 it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900