[Mono-devel-list] XML deserialization - System.FormatException on System.DateTime.ParseExact()

Hickey, Damian (Exchange) DHickey at Bear.com
Fri May 27 06:46:58 EDT 2005


Hi Atsushi,

Thank you for your reply :)

I do have an XSD that describes that piece of XML and the type is
xs:date, I am using a codegen tool (a modified xsd.exe) to create
classes from the XSD; the output of which, "PublishedDate" type is
System.DateTime, and has an attribute
[System.Xml.Serialization.XmlElementAttribute(DataType="date")]. 

According to W3C, xs:date can have an optional timezone property
(http://www.w3.org/TR/xmlschema-2/#date) so "yyyy-MM-dd" pattern will
fail if a timezone is present.

Your patch seems resemble the output from MS.NET serializer on my class,
which is:

o. at PublishDate = ToDate(Reader.ReadElementString());

Thanks again, looking forward to 1.1.8!

- Damian



-----Original Message-----
From: Atsushi Eno [mailto:atsushi at ximian.com] 
Sent: 26 May 2005 17:17
To: Hickey, Damian (Exchange)
Cc: mono-devel-list at lists.ximian.com; Lluis Sanchez
Subject: Re: [Mono-devel-list] XML deserialization -
System.FormatException on System.DateTime.ParseExact()

Hello,

> System.Reflection.TargetInvocationException: Exception has been thrown
> by the target of an invocation. ---> System.FormatException: Invalid
> format.
> 
> in <0x000fe> System.DateTime:ParseExact (System.String s,
> System.String[] formats, IFormatProvider fp, DateTimeStyles style)
> 
> in <0x00040> System.DateTime:ParseExact (System.String s,
System.String
> format, IFormatProvider fp, DateTimeStyles style)
> 
> in <0x00019> System.DateTime:ParseExact (System.String s,
System.String
> format, IFormatProvider fp)
> 
> in <0x0050f>
>
Mono.GeneratedSerializers.Literal.GeneratedReader:ReadObject_InventoryPo
> sitionBaseData (Boolean isNullable, Boolean checkType)

> ob. at PublishDate = DateTime.ParseExact (Reader.ReadElementString (),
> "yyyy-MM-dd", CultureInfo.InvariantCulture);
> 
> The problem here is that the datetime in the xml does not, and
probably
> never will, match the format (2nd parameter) in the above statement.
> This format does not take into account a time or timezone component
i.e.
> 2005-05-26T16:01:36+01:00

Maybe your "PublishedDate" is xs:date, since "yyyy-MM-dd" pattern
is used only for xs:date type. If the type is xs:dateTime, then
XmlConert.ToDateTime() will be used (and it allows many more
patterns). If it is allowed in MS.NET, maybe attached patch will
fix it.

Lluis: maybe you can check the patch sanity?

Atsushi Eno





**********************************************************************
Please be aware that, notwithstanding the fact that the person sending
this communication has an address in Bear Stearns' e-mail system, this
person is not an employee, agent or representative of Bear Stearns.
Accordingly, this person has no power or authority to represent, make
any recommendation, solicitation, offer or statements or disclose
information on behalf of or in any way bind Bear Stearns or any of its
affiliates.
**********************************************************************




More information about the Mono-devel-list mailing list