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

Hickey, Damian (Exchange) DHickey at Bear.com
Thu May 26 11:05:54 EDT 2005


Hi All,

 

This is my first foray into the land of Mono after a few years on MS
.Net. and am very happy with the level of compatibility. I've just
subbed to this mailing list, so if I break any rules do let me know...

 

I'm having a problem with XML deserialization and am wondering if it's a
bug related to 71290 (http://bugzilla.ximian.com/show_bug.cgi?id=71290)
or not and if anyone can help? The code works under MS.Net 1.1, but not
Mono 1.1.7 (on Windows XP).

 

So I have this simple piece of xml:

 

<InventoryPositionBase
xmlns="urn:company.com:Application.Messages:v1.0">

  <ProductId>9496</ProductId>

  <PortfolioId>175</PortfolioId>

  <PublishDate>2005-05-25-04:00</PublishDate>

</InventoryPositionBase>

 

And during deserialization the following exception is thrown:

 

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)

in <0x00086>
Mono.GeneratedSerializers.Literal.GeneratedReader:ReadRoot_InventoryPosi
tionBaseData ()

in <0x00000> <unknown method>

in (wrapper managed-to-native)
System.Reflection.MonoMethod:InternalInvoke (object,object[])

in <0x0006f> System.Reflection.MonoMethod:Invoke (System.Object obj,
BindingFlags invokeAttr, System.Reflection.Binder binder ,
System.Object[] parameters, System.Globalization.CultureInfo culture)

--- End of inner exception stack trace ---

in <0x00104> System.Reflection.MonoMethod:Invoke (System.Object obj,
BindingFlags invokeAttr, System.Reflection.Binder binder,
System.Object[] parameters, System.Globalization.CultureInfo culture)

in <0x00017> System.Reflection.MethodBase:Invoke (System.Object obj,
System.Object[] parameters)

in <0x00073> System.Xml.Serialization.XmlSerializer:Deserialize
(System.Xml.Serialization.XmlSerializationReader reader)

in <0x0004a> System.Xml.Serialization.XmlSerializer:Deserialize
(System.Xml.XmlReader xmlReader)

in <0x0003c> System.Xml.Serialization.XmlSerializer:Deserialize
(System.IO.TextReader textReader)

in <0x00091> Messages.Utility:Deserialize (System.Byte[] msg,
System.Type type)

in <0x0009c> ...

 

I managed to grab the emitted code that performs the xml to object
parsing and it looks like the problem occurs when parsing the
<PublishDate> element during the ReadObject_InventoryPositionBaseData
method.  The offending line of code:

 

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

 

Is this a bug or have I done something completely wrong?

 

Help and ideas appreciated.

 

All the best,

 

Damian

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20050526/5b984227/attachment.html 
-------------- next part --------------


**********************************************************************
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