[Mono-bugs] [Bug 53246][Nor] New - XmlSerialization: Derived types must be included by their direct parents.

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Fri, 23 Jan 2004 07:52:03 -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 erezl@mainsoft.com.

http://bugzilla.ximian.com/show_bug.cgi?id=53246

--- shadow/53246	2004-01-23 07:52:03.000000000 -0500
+++ shadow/53246.tmp.24231	2004-01-23 07:52:03.000000000 -0500
@@ -0,0 +1,151 @@
+Bug#: 53246
+Product: Mono/Class Libraries
+Version: unspecified
+OS: All
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: Sys.XML
+AssignedTo: lluis@ximian.com                            
+ReportedBy: erezl@mainsoft.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Summary: XmlSerialization: Derived types must be included by their direct parents.
+
+Please fill in this template when reporting a bug, unless you know what 
+you are doing.
+Description of Problem:
+If a type is not included by its direct parent, but by a higher class in 
+the hirarchy, then the xml serializer does not recognize it.
+
+Steps to reproduce the problem:
+1. Compile and run the following sample:
+public class Deserializer
+{
+	static void Main(string[] args)
+	{		
+		XmlSerializer serializer = new XmlSerializer(typeof
+(Vehicle));
+		Vehicle o;
+
+		o = new Truck();
+		o.Make = "Peugeut";
+		o.Model = "206";
+		o.Year = 2004;
+		((Truck)o).VIN = "asdad";
+		((Truck)o).Load = 15;
+
+		System.IO.TextWriter sout = Console.Out;
+		serializer.Serialize(sout, o);
+		sout.Close();
+	}
+
+}
+
+
+
+[XmlInclude(typeof(Car))]
+[XmlInclude(typeof(Motorcycle))]
+[XmlInclude(typeof(Truck))]
+public class Vehicle
+{
+	public Vehicle(){}
+	public string Make;
+	public string Model;
+	public int Year;
+
+	public override string ToString()
+	{
+		string s = string.Empty;
+		s+= "Make: " + Make + " ";
+		s+= "Model: " + Model + " ";
+		s+= "Year: " + Year + " ";
+		return s;
+	}
+
+}
+
+public class Car : Vehicle
+{
+	public Car() {}
+	public string VIN;
+	
+	public override string ToString()
+	{
+		string s = base.ToString();
+		s+= "VIN: " + VIN + " ";
+		return s;
+	}
+
+}
+public class Motorcycle : Vehicle
+{
+	public Motorcycle() {}
+	public double ZeroTo100;
+
+	public override string ToString()
+	{
+		string s = base.ToString ();
+		s += "ZeroTo100: " + ZeroTo100.ToString() + " ";
+		return s;
+	}
+
+}
+
+public class Truck : Car
+{
+	public int Load;
+	public override string ToString()
+	{
+		string s = base.ToString ();
+		s += "Load: " + Load + " ";
+		return s;
+	}
+
+}
+
+Actual Results:
+I get the following exception:
+<?xml version="1.0" encoding="utf-8"?>
+<Vehicle
+Unhandled Exception: System.InvalidOperationException: Invalid type: 
+ConsoleApplication4.Truck
+in <0x00142> 
+System.Xml.Serialization.XmlSerializationWriter:WriteTypedPrimitive 
+(string,string,object,bool)
+in <0x001f0> 
+System.Xml.Serialization.XmlSerializationWriterInterpreter:WriteObject 
+(System.Xml.Serialization.XmlTypeMapping,object,string,string,bool,bool,bo
+ol)
+in <0x0013a> 
+System.Xml.Serialization.XmlSerializationWriterInterpreter:WriteObject 
+(object)
+in <0x0007d> System.Xml.Serialization.XmlSerializer:Serialize 
+(object,System.Xml.Serialization.XmlSerializationWriter)
+in <0x000e6> System.Xml.Serialization.XmlSerializer:Serialize 
+(System.Xml.XmlWriter,object,System.Xml.Serialization.XmlSerializerNamespa
+ces)
+in <0x0005f> System.Xml.Serialization.XmlSerializer:Serialize 
+(System.IO.TextWriter,object)
+in <0x000d9> ConsoleApplication4.Deserializer:Main (string[])
+
+
+Expected Results:
+In .NET:
+<?xml version="1.0" encoding="utf-8"?>
+<Vehicle xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
+xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Truck">
+  <Make>Peugeut</Make>
+  <Model>206</Model>
+  <Year>2004</Year>
+  <VIN>asdad</VIN>
+  <Load>15</Load>
+</Vehicle>
+
+How often does this happen? 
+Always.
+
+Additional Information: