Saturday, March 24, 2012

Operator is not valid for type ArrayList and string "".

can anyone help me with this?

Code Snippet:
Dim ArrCart As New ArrayList()
if NOT Session("sesCart") = "" then
ArrCart = Session("sesCart")

Error:
System.InvalidCastException: Operator is not valid for type 'ArrayList' and
string "".
Line 26: if NOT Session("sesCart") = "" then

Thanks in advance
marcMarc,

I see two potential mistakes in this code.

> Dim ArrCart As New ArrayList()

Here, you are creating an instance of an arraylist. This is fine

> ArrCart = Session("sesCart")

Here you are assigning whatever is in 'Session("sesCart")' to 'ArrCart',
overwriting the instance that you declared above.

The error is probably being raised because 'Session("sesCart")' does not
contain an instance of an arraylist - it looks like it contains a string
instead. Make sure of what you are assigning to your variables.

Hope this helps,

Trev.

"Marc Bishop" <nonotospammarcbishop@.hotmail.com> wrote in message
news:bcwqb.18$Ae2.10@.news-binary.blueyonder.co.uk...
> can anyone help me with this?
> Code Snippet:
> Dim ArrCart As New ArrayList()
> if NOT Session("sesCart") = "" then
> ArrCart = Session("sesCart")
> Error:
> System.InvalidCastException: Operator is not valid for type 'ArrayList'
and
> string "".
> Line 26: if NOT Session("sesCart") = "" then
> Thanks in advance
> marc

0 comments:

Post a Comment