1
votes

So I track different users access through GUID. It has worked great up until now and I dont understand why its failing.

I am assigning the variable, then I check for null, then run the code, and then it throws the nullreferenceexception error. Here is the code:

    if (String.IsNullOrEmpty(Session["GUID"] as string))
    {
        Server.Transfer("~/index.aspx", true);
    }
    else
    {
        GUID = Session["GUID"].ToString();
        if (!String.IsNullOrEmpty(GUID))
        {
            itemID = (int)aooDB_Items.SelectItemID(GUID);
        }
    }

The NullReferenceException is being thrown in the aooDB_Items.SElectItemID(GUID) line

Update: I also tried setting GUID = "none" and then checking to make sure its not "none" before running the code. The code runs each time and if I put a breakpoint in anywhere I can see that GUID has a GUID as a value which makes this more confusing.

Error:

    An exception of type 'System.NullReferenceException' occurred in App_Web_3hq5xlxh.dll but was not handled in user code

    Additional information: Object reference not set to an instance of an object.
1
Post the error message as well - Spaceman Spiff
Maybe aooDB_Items is null? - Robby Cornelissen
You are probably trying to cast to int a null value. Check if SelectItemID is returning a valid value. - InBetween
if (!String.IsNullOrEmpty(GUID)) is redundant. - Sriram Sakthivel
added the error and checking to see if SelectItemID is the problem. SelectItemID works on a different page that is laid out exactly the same. - xCasper

1 Answers

1
votes

InBetween and Robby Cornelissen helped me solve this problem. The issue was that SelectItemID was sending back nothing.