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

  • Thread starter Thread starter Marc Bishop
  • Start date Start date
M

Marc Bishop

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
 
Marc,

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.
 
Back
Top