[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, 25 Dec 2003 06:33:42 -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 jaak@zd.com.pl.


--- shadow/52557	2003-12-25 06:33:42.000000000 -0500
+++ shadow/52557.tmp.31845	2003-12-25 06:33:42.000000000 -0500
@@ -0,0 +1,110 @@
+Bug#: 52557
+Product: Mono/Class Libraries
+Version: unspecified
+OS: All
+OS Details: 
+Status: NEW   
+Priority: Normal
+Component: System.XML
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: jaak@zd.com.pl               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+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>
+fails validation / deserialization when used on a class:
+[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 
+in <0x00011> 
+ttribute (object)
+in <0x007f7> 
+in <0x00058> 
+ceMembers (System.Xml.Serialization.XmlTypeMapping,object)
+in <0x0021e> 
+ce (System.Xml.Serialization.XmlTypeMapping,bool,bool)
+in <0x00067> 
+in <0x000dc> 
+in <0x00098> 
+System.Xml.Serialization.XmlSerializationReaderInterpreter:ReadObject ()
+in <0x00075> System.Xml.Serialization.XmlSerializer:Deserialize 
+in <0x00068> System.Xml.Serialization.XmlSerializer:Deserialize 
+in <0x000ee> .Class1:Main (string[])
+Expected Results:
+No exceptions. The missing field should (???) be ignored as in MS 
+How often does this happen? 
+Every time.
+Additional Information:
+Mono behaviour is different from MS here. I'm not sure which one is