Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

System.InvalidCastException

Status
Not open for further replies.

23maploosh

Programmer
Mar 9, 2009
5
CA
I have a windows application that was built with vs2003. One part of the application uses a xml file to adjust the formatting of questions that are being displayed. The problem here is that the application uses the lines,

dim size as integer
size = "14.25" (this is actually a string being parsed to pull out the 14.25, but works out to setting size = "14.25")

Now this application has been running on several machines without any problems and then last week someone emailed me saying they were getting a System.InvalidCastException. I investigated the error and it pointed to the code listed above. I know how to fix the error and I should never of left it like this in the first place but I am wondering if anyone knows why it works on certain machines and then errors out on another. Any ideas would be appreciated.
Thanks
Matt

 
Well, are you sure in the case where the exception occurred that the string value was actually 14.25? Maybe some non-numeric data was passed in.

Other than that, the only thing I can think of would be the regional settings on the pc where the exception is being thrown. If it's set to something where a period is not a decimal place, then that could be your issue.
 
I'm surprised it worked anywhere. Your trying to use a decimal as an integer. It looks like your trying to cast a string to an integer, however, your returning a decimal (14.25).
 
Good call, I completely missed that. However, it should still implicitly convert and round that decimal to an integer unless Option Strict is on.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top