Help with InvalidCastException

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?Q2hyaXM=?=

    Help with InvalidCastException

    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("MainMen u")) = Nothing Then
    ...
    nodeCollection = menudal.FetchMe nu()
    Cache.Insert("M ainMenu", nodeCollection)
    End If

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

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

    at the line If (Cache("MainMen u")) = Nothing Then

    Any ideas?

  • Dave Sexton

    #2
    Re: Help with InvalidCastExce ption

    Hi,

    It's been a while since I did VB but I think you have to use "Is Nothing"
    not "= Nothing" for a comparison.

    --
    Dave Sexton


    "Chris" <Chris@discussi ons.microsoft.c omwrote in message
    news:70DB84E1-E082-421D-9765-6535C689675E@mi crosoft.com...
    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("MainMen u")) = Nothing Then
    ...
    nodeCollection = menudal.FetchMe nu()
    Cache.Insert("M ainMenu", nodeCollection)
    End If
    >
    Then I read from Cache to populate my menu. When I run the project though,
    I
    get
    >
    "InvalidCastExc eption"
    Operator '=' is not defined for type 'List(Of MenuNode)' and 'Nothing'.
    >
    at the line If (Cache("MainMen u")) = Nothing Then
    >
    Any ideas?
    >

    Comment

    • RobinS

      #3
      Re: Help with InvalidCastExce ption

      You're correct. Or you can check "IsNot Nothing" if you're feeling
      contrary.

      Robin S.
      ---------------------
      "Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
      news:%23PkNA6gK HHA.1252@TK2MSF TNGP02.phx.gbl. ..
      Hi,
      >
      It's been a while since I did VB but I think you have to use "Is
      Nothing" not "= Nothing" for a comparison.
      >
      --
      Dave Sexton

      >
      "Chris" <Chris@discussi ons.microsoft.c omwrote in message
      news:70DB84E1-E082-421D-9765-6535C689675E@mi crosoft.com...
      >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("MainMen u")) = Nothing Then
      > ...
      > nodeCollection = menudal.FetchMe nu()
      > Cache.Insert("M ainMenu", nodeCollection)
      >End If
      >>
      >Then I read from Cache to populate my menu. When I run the project
      >though, I
      >get
      >>
      >"InvalidCastEx ception"
      >Operator '=' is not defined for type 'List(Of MenuNode)' and
      >'Nothing'.
      >>
      >at the line If (Cache("MainMen u")) = Nothing Then
      >>
      >Any ideas?
      >>
      >
      >

      Comment

      Working...