[Mono-bugs] [Bug 52557][Nor] New - XmlSerializer + XmlValidatingReader fail on not-existing default attributes.
bugzilla-daemon@bugzilla.ximian.com
bugzilla-daemon@bugzilla.ximian.com
Thu, 8 Jan 2004 07:21:56 -0500 (EST)
Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.
Changed by lluis@ximian.com.
http://bugzilla.ximian.com/show_bug.cgi?id=52557
--- shadow/52557 2004-01-08 07:21:56.000000000 -0500
+++ shadow/52557.tmp.23351 2004-01-08 07:21:56.000000000 -0500
@@ -0,0 +1,118 @@
+Bug#: 52557
+Product: Mono/Class Libraries
+Version: unspecified
+OS: All
+OS Details:
+Status: RESOLVED
+Resolution: FIXED
+Severity: Unknown
+Priority: Normal
+Component: System.XML
+AssignedTo: mono-bugs@ximian.com
+ReportedBy: jaak@zd.com.pl
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: XmlSerializer + XmlValidatingReader fail on not-existing default attributes.
+
+Description of Problem:
+
+XmlSerializer when used with XmlValidatingReader fails for fields that
+are defined in schema but not in CLR classes. It happens for fields that
+have "default" attribute defined in XSD.
+
+This simple file:
+==============
+<?xml version="1.0" encoding="utf-8"?>
+<root xmlns="http://tempuri.org/"></root>
+==============
+
+with this schema:
+==========
+<?xml version="1.0" encoding="utf-8" ?>
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:test="http://tempuri.org/"
+ elementFormDefault="qualified"
+ targetNamespace="http://tempuri.org/"
+ xmlns="http://tempuri.org/">
+
+ <xsd:element name="root" type="test:RootInfo" />
+
+ <xsd:complexType name="RootInfo">
+ <xsd:attribute name="attribute1" use="optional"
+type="xsd:boolean" default="false" />
+ </xsd:complexType>
+</xsd:schema>
+==========
+
+fails validation / deserialization when used on a class:
+
+==========
+[XmlType(Namespace="http://tempuri.org/")]
+[XmlRoot("root", Namespace="http://tempuri.org/", IsNullable=false)]
+public class RootInfo
+{
+ // UNCOMMENT this and the problem goes away
+ // [XmlAttribute("attribute1")]
+ // public bool attribute1;
+}
+==========
+
+Steps to reproduce the problem:
+1. Compile the attached program and run it.
+
+Actual Results:
+
+An exception thrown:
+Unhandled Exception: System.InvalidCastException: Cannot cast from source
+type to destination type
+in <0x00374> System.Xml.Serialization.XmlSerializationReader:UnknownNode
+(object)
+in <0x00011>
+System.Xml.Serialization.XmlSerializationReaderInterpreter:ProcessUnknownA
+ttribute (object)
+in <0x007f7>
+System.Xml.Serialization.XmlSerializationReaderInterpreter:ReadMembers
+(System.Xml.Serialization.ClassMap,object,bool,bool)
+in <0x00058>
+System.Xml.Serialization.XmlSerializationReaderInterpreter:ReadClassInstan
+ceMembers (System.Xml.Serialization.XmlTypeMapping,object)
+in <0x0021e>
+System.Xml.Serialization.XmlSerializationReaderInterpreter:ReadClassInstan
+ce (System.Xml.Serialization.XmlTypeMapping,bool,bool)
+in <0x00067>
+System.Xml.Serialization.XmlSerializationReaderInterpreter:ReadObject
+(System.Xml.Serialization.XmlTypeMapping,bool,bool)
+in <0x000dc>
+System.Xml.Serialization.XmlSerializationReaderInterpreter:ReadRoot
+(System.Xml.Serialization.XmlTypeMapping)
+in <0x00098>
+System.Xml.Serialization.XmlSerializationReaderInterpreter:ReadObject ()
+in <0x00075> System.Xml.Serialization.XmlSerializer:Deserialize
+(System.Xml.Serialization.XmlSerializationReader)
+in <0x00068> System.Xml.Serialization.XmlSerializer:Deserialize
+(System.Xml.XmlReader)
+in <0x000ee> .Class1:Main (string[])
+
+Expected Results:
+
+No exceptions. The missing field should (???) be ignored as in MS
+implementation.
+
+How often does this happen?
+
+Every time.
+
+Additional Information:
+
+Mono behaviour is different from MS here. I'm not sure which one is
+correct.
+
+------- Additional Comments From jaak@zd.com.pl 2003-12-25 06:41 -------
+Created an attachment (id=6328)
+test case to reproduce the problem
+
+
+------- Additional Comments From lluis@ximian.com 2004-01-08 07:21 -------
+Fixed in CVS. Thanks!