c# - Cannot convert string to DateTime within a LINQ expression -


i using linq xml expression deserialize xml data list of objects. object collection fields:

public class dataobject {  private string name { get; set; }  private datetime date { get; set; } }  

and here's linq query:

xdocument linqxml = xdocument.parse(datatodeserialize.outerxml) list<dataobject> myobjects = (from object in linqxml.descendants("object") select new dataobject {  name = object.element("name").value,  date = convert.todatetime(object.element("date").value) }  

when run this, linq query throws formatexception: "string not recognized valid datetime."

the date string in xml formatted in utc: 2013-05-02t11:25:35-06:00

to test tried conversion of date time , correctly returns datetime object.

datetime dt = convert.todatetime("2013-05-02t11:25:35-06:00"); 

and string converts new datetime object. if switch date field on object string type, , convert in method, converts. seems not work when part of linq query.

i'm stumped on one. i've tried using datetime.parse(string) well, throws same exception. there way conversion within query or have convert fields after objects have been created?

edited add:

sample xml: attributes in each tag generated transaction engine i'm querying data. pulled text of xml while debugging , there appears no additional whitespace between date tags.

<object>  <name __generictype="string" __specifictype="[string]" __nodetype="datafield">hellothere</name>  <date __generictype="timestamp" __specifictype="[timestamp]" __nodetype="datafield">2013-05-12t11:08:04-06:00</date> </object> 


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -