string[] arrUserRoles = {}; <-- call this line a
arrUserRoles = (string[]) HttpContext.Current.Items["UserRoles"]; <--- Call
this line b. error on this line
Label1.Text = arrUserRoles.Length.ToString();

If I comment out line b it works (displays 0 as it should). If I put line b
back in it throws the error.

Any suggestions on what's wrong?

Also, how do I test for the context variable arrUserRoles being defined?

You're not looking at the actual exception being thrown - the message
just happens to be the message given by the exception. Look up
NullReferenceException instead and you'll find a bit of information.

The first thing I look at when an exception is thrown is the type of
exception, not the message.

In addition to what Jon's mentioned - it might be worth debugging your code
and see on what line you are actually getting this error. Then, all you do
is print the values of the objects used on that line in the Command Window,
and you know you are trying to use a null object as if it was a properly
referenced object.

You're not looking at the actual exception being thrown - the message just happens to be the message given by the exception. Look up NullReferenceException instead and you'll find a bit of information.

The first thing I look at when an exception is thrown is the type of exception, not the message.

In addition to what Jon's mentioned - it might be worth debugging your codeand see on what line you are actually getting this error. Then, all you dois print the values of the objects used on that line in the Command Window,and you know you are trying to use a null object as if it was a properlyreferenced object.

The error message is clear as crystal.

Cheers,Wim Hollebrandse

I must be running a different program!

I am more used to Borland compilers, when they pop up with an error
message I press 'F1' and it takes me to an explanation of the error -
which I find useful.

In VS7 pressing 'F1' tells me there has been an error, well I know
that, what I want is information on avoiding it.

Searching for 'NullReferenceException' as suggested by Jon leads to a
not very exciting explanation of how to construct a
NullReferenceException object, I don't want to thanks, I just got one
automagically!

The meaning of the error looks clear on the face of it but when
calling the Win API, as I said earlier, it is this error that gets
thrown up if a parameter is wrong, and that is not very helpful.

Anyway I doubt if this helps the original writer who by now has
probably analysed the problem line, fixed it and is writing his next
program :-)