Select to view content in your preferred language

Casting GeoRssLayer's PublishDate to DateTime return InvalidCastException

823
4
08-10-2010 03:15 AM
linusang
Emerging Contributor
hi i tried this code but it returns me InvalidCastException

DateTime eqDateTime = (DateTime)g.Attributes["PublishDate"];
0 Kudos
4 Replies
MartenLiebster
Deactivated User
hi i tried this code but it returns me InvalidCastException

DateTime eqDateTime = (DateTime)g.Attributes["PublishDate"];


Have you put a breakpoint on the line? What does the PublishDate hold?

Is it a string? If so, you might need to do a DateTime.Parse() or DateTime.TryParse().

** added ***

Or the date might just be in an invalid format. Thus the first line of questions above.
0 Kudos
linusang
Emerging Contributor
it is in DateTime type... as documented here

http://help.arcgis.com/en/webapi/silverlight/apiref/api_start.htm
0 Kudos
JenniferNery
Esri Regular Contributor
You can do the following:
  DateTime dt = ((DateTimeOffset)g.Attributes["PublishDate"]).DateTime;


Jennifer
0 Kudos
linusang
Emerging Contributor
You can do the following:
  DateTime dt = ((DateTimeOffset)g.Attributes["PublishDate"]).DateTime;


Jennifer


thanks it works
0 Kudos