How to deal with this Exception : System.InvalidCastException: Ö¸¶¨µÄת»»ÎÞЧ¡£

  • Thread starter Thread starter DogEye
  • Start date Start date
D

DogEye

The page always throw the InvalidCastException When i do some conversion .
and tell me that "System.InvalidCastException: Ö¸¶¨µÄת»»ÎÞЧ" , how to deal
with this problem ?

Thanks !
 
Hello,
What kind of conversions do you do exactly? A little bit of code
snippet will help to know the exact problem.

Cheers
Maqsood Ahmed [MCP,C#]
Kolachi Advanced Technologies
http://www.kolachi.net
 
foreach(object obj in entity.Properties)
{
EntityProperty prop = (EntityProperty)obj ;

}
EntityProperty is the self-defined type ,and entity.Properties is an
ArrayList which saves a list of EntityProperty variables .
 
Hello

foreach(object obj in entity.Properties)
{
try {
EntityProperty prop = (EntityProperty)obj ;
}
catch (InvalidCastException e){
// do some error handling
}
}

If you wonder why this cast fails... then try view with the debugger
the nested types of obj... EntityProperty must be sub classs!

Greets, Sebastian Dau
 
Back
Top