Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
TitleResolve Invalid Cast exceptions
KeywordsInvalid Cast exception, VB.NET
CategoriesVB.NET
 
I was calling a BinaryFormatter object's methods and getting an Invalid Cast exception. That should have meant that I was trying to convert an object from one data type to an incompatible data type, but I was assigning the returned result to an object of the correct type.

After much head scratching, I discovered that I was passing the method an argument of the wrong type. The development environment (Beta 2) thought the type was ok but the BinaryFormatter couldn't handle it.

Moral: If you get an Invalid Cast exception, look first at the type of the variable to which you are assigning the result. Then look at the type of the object you are passing into the routine.

Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated