[Mono-dev] [Mono-patches] r109263 - trunk/mcs/class/System.Data/System.Data

Atsushi Eno atsushi at ximian.com
Wed Jul 30 11:03:17 EDT 2008


Hey,

I tried the repro case on that bug and verified it works under .NET.
Then I removed the parameterless constructor. .NET borked.

That means, instead of using XmlReader.ReadContentAsObject(),
you would simply write like below.

--------
IXmlSerializable x = (IXmlSerializable) Activator.CreateInstance (
   col.DataType, new object [0]);
if (!reader.IsEmptyElement) {
   reader.ReadStartElement ();
   reader.MoveToContent ();
   x.ReadXml (reader);
   reader.ReadEndElement ();
}
else
   reader.Skip ();
row [col] = x; // not sure if it is filled in case of empty element...
--------

Atsushi Eno


Rodrigo Kumpera wrote:
> Varadhan,
> 
> Depending on exception on regular paths might lead to disastrous 
> performance.
> Is this just a corner case for compatibility or this kind of situation 
> might happen often?
> We might need to document this shortcoming of our stack.
> 
> Thanks,
> Rodrigo
> 
> 
> On Wed, Jul 30, 2008 at 10:56 AM, Veerapuram Varadhan 
> (vvaradhan at novell.com <mailto:vvaradhan at novell.com>) 
> <mono-patches-list at lists.ximian.com 
> <mailto:mono-patches-list at lists.ximian.com>> wrote:
> 
>     Author: varadhan
>     Date: 2008-07-30 09:56:01 -0400 (Wed, 30 Jul 2008)
>     New Revision: 109263
> 
>     Modified:
>       trunk/mcs/class/System.Data/System.Data/ChangeLog
>       trunk/mcs/class/System.Data/System.Data/XmlDataReader.cs
>     Log:
>     Fixes##377146 - handle custom reference types sanely when reading from
>     an XML file
> 
> 
>     Modified: trunk/mcs/class/System.Data/System.Data/ChangeLog
>     ===================================================================
>     --- trunk/mcs/class/System.Data/System.Data/ChangeLog   2008-07-30
>     13:40:00 UTC (rev 109262)
>     +++ trunk/mcs/class/System.Data/System.Data/ChangeLog   2008-07-30
>     13:56:01 UTC (rev 109263)
>     @@ -1,3 +1,8 @@
>     +2008-07-29  Veerapuram Varadhan  <vvaradhan at novell.com
>     <mailto:vvaradhan at novell.com>>
>     +
>     +       Fixes ##377146
>     +       * XmlDataReader.cs (ReadElementElement): Handle custom
>     reference types sanely.
>     +
>      2008-07-20  Gert Driesen  <drieseng at users.sourceforge.net
>     <mailto:drieseng at users.sourceforge.net>>
> 
>            * DataColumnCollection.cs (IndexOf): Include name of column -
>     for which
> 
>     Modified: trunk/mcs/class/System.Data/System.Data/XmlDataReader.cs
>     ===================================================================
>     --- trunk/mcs/class/System.Data/System.Data/XmlDataReader.cs  
>      2008-07-30 13:40:00 UTC (rev 109262)
>     +++ trunk/mcs/class/System.Data/System.Data/XmlDataReader.cs  
>      2008-07-30 13:56:01 UTC (rev 109263)
>     @@ -26,6 +26,7 @@
>      using System.IO;
>      using System.Data;
>      using System.Xml;
>     +using System.Xml.Serialization;
> 
> 
>      namespace System.Data
>     @@ -297,7 +298,27 @@
> 
>                                    bool wasEmpty = reader.IsEmptyElement;
>                                    int depth = reader.Depth;
>     -                               row [col] = StringToObject
>     (col.DataType, reader.ReadElementString ());
>     +
>     +                               if (typeof
>     (IXmlSerializable).IsAssignableFrom (col.DataType)) {
>     +#if NET_2_0
>     +                                       try {
>     +                                               // NOTE:
>     ReadElementString works fine with proper XML with CDATA etc,
>     +                                               // however doesn't
>     behave well with XMLs like the one in
>     +                                               //
>     https://bugzilla.novell.com/show_bug.cgi?id=377146 which is
>     +                                               // apparently
>     supported by MS.NET <http://MS.NET> - to maintain compatibility,
>     +                                               // Try reading the
>     element content as an object type
>     +                                               row [col] =
>     reader.ReadContentAsObject ();
>     +                                       } catch {
>     +#endif
>     +                                               // XML is not in
>     accordance to expected standards, try reading the content as an xml doc
>     +                                               row [col] =
>     reader.ReadInnerXml ();
>     +#if NET_2_0
>     +                                       }
>     +#endif
>     +                               } else {
>     +                                       row [col] = StringToObject
>     (col.DataType, reader.ReadElementString ());
>     +                               }
>     +
>                                    if (!wasEmpty && reader.Depth > depth) {
>                                    // This means, instance does not
>     match with
>                                    // the schema (because the instance
>     element
> 
>     _______________________________________________
>     Mono-patches maillist  -  Mono-patches at lists.ximian.com
>     <mailto:Mono-patches at lists.ximian.com>
>     http://lists.ximian.com/mailman/listinfo/mono-patches
> 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list



More information about the Mono-devel-list mailing list