xCasper
xCasper

Reputation: 123

NullReferenceException thrown after null check?

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.

Upvotes: 1

Views: 257

Answers (1)

xCasper
xCasper

Reputation: 123

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

Upvotes: 1

Related Questions