1

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.
8
  • Post the error message as well Commented Aug 16, 2014 at 7:05
  • 8
    Maybe aooDB_Items is null? Commented Aug 16, 2014 at 7:07
  • 1
    You are probably trying to cast to int a null value. Check if SelectItemID is returning a valid value. Commented Aug 16, 2014 at 7:09
  • 1
    if (!String.IsNullOrEmpty(GUID)) is redundant. Commented Aug 16, 2014 at 7:09
  • 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. Commented Aug 16, 2014 at 7:10

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.