Archive for May 19, 2007

Invalid cast from ‘System.String’ to ‘System.TimeSpan….

I have already mentioned in one of my previous blog articles, I am working on a web application which has been converted from 1.1 to 2.0. And because of the many minor changes made in the 2.0 framework, I keep encountering many exceptions!!!

One such exception was raised while making use of Convert.ChangeType method.

When i tried to convert a string to timespan an InvalidCastException was raised. Reason??? In this framework, the method does not support this type of a conversion….

There is the option of using Parse method or TryParse method in TimeSpan class… (TryParse is a newly added method which is very much similar to the Parse method but this doesn’t throw an exception when the conversion fails).

Another thing to keep in mind while using this method is that it doesn’t handle nullables.

Advertisements

May 19, 2007 at 3:46 am 1 comment


May 2007
M T W T F S S
« Apr   Jun »
 123456
78910111213
14151617181920
21222324252627
28293031