Help with InvalidCastException

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I have a problem with part of my code. I am trying to Cache a Generic
Collection

Private nodeCollection As New Generic.List(Of MenuNode)

If (Cache("MainMenu")) = Nothing Then
...
nodeCollection = menudal.FetchMenu()
Cache.Insert("MainMenu", nodeCollection)
End If

Then I read from Cache to populate my menu. When I run the project though, I
get

"InvalidCastException"
Operator '=' is not defined for type 'List(Of MenuNode)' and 'Nothing'.

at the line If (Cache("MainMenu")) = Nothing Then

Any ideas?
 
Hi,

It's been a while since I did VB but I think you have to use "Is Nothing"
not "= Nothing" for a comparison.
 
You're correct. Or you can check "IsNot Nothing" if you're feeling
contrary.

Robin S.
---------------------
 
Back
Top