473,322 Members | 1,421 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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("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?

Dec 27 '06 #1
2 987
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
http://davesexton.com/blog

"Chris" <Ch***@discussions.microsoft.comwrote in message
news:70**********************************@microsof t.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("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?

Dec 27 '06 #2
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:%2****************@TK2MSFTNGP02.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
http://davesexton.com/blog

"Chris" <Ch***@discussions.microsoft.comwrote in message
news:70**********************************@microsof t.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("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?


Dec 28 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Johan Appelgren | last post by:
Hi, I'm trying to serialize a class hierarchy using System.Xml.Serialization.XmlSerializer from a class that is loaded as a Com object. But it fails with a InvalidCastException. I don't know...
1
by: bob scola | last post by:
I have a csharp, VS 2003 solution for a winform application The application uses an object called a "matter" and the class is defined in matter.cs. I can load matter objects into a combobox ...
4
by: Tressa | last post by:
I have a messagebox that I only want to pop up only if it is not already being displayed on the screen. My code is still poping up the messagebox even though it is on the screen. What am I doing...
4
by: Tyro | last post by:
Can someone shed some light on my error here? Thanks! Specified cast is not valid. Exception Details: System.InvalidCastException: Specified cast is not valid. Source Error: Stack Trace:
4
by: DOTNET | last post by:
Hi, Anybody help me regarding this error: I am assigning the values to the session variables when the button is clicked and passing these session variables to the next page and when I am...
0
by: QA | last post by:
I am using a Business Scorecard Accelarator in a Sharepoint Portal 2003 using SQL Server 2005 I am getting the following error: Error,5/7/2005 10:50:14 AM,580,AUE1\Administrator,"Specified cast is...
3
by: dan heskett | last post by:
Hello group, I am trying to get used to vb.net coming from a far far far away set of tools. What i want to do is setup an object in my application that contains other object types, that act...
4
by: Brad Isaacs | last post by:
I am using ASP.NET 2.0 codebehind Visual Basic, Visual Studio 2005 Working with DataSet creating a Data Access Layer via VS 2005. My error is when the code that is prewritten by VS 2005 Casts...
2
by: Brad Isaacs | last post by:
ASp.NET 2.0 , Visual Studio 2005 I am working with the Add NEw Item >DataSet I have created my Dataset and call it, when I run my project, I receive an error message because the dataset is...
8
by: Joe HM | last post by:
Hello - I was wondering that the "cleanest" way is to determine whether a CType() will throw an InvalidCastException? I have data I receive as an Object and I want to convert it to a String...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.