[Mono-bugs] [Bug 52607][Blo] New - enum serialization is not fully compatibly with Microsoft.
bugzilla-daemon@bugzilla.ximian.com
bugzilla-daemon@bugzilla.ximian.com
Mon, 5 Jan 2004 11:29: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 mordechait@mainsoft.com.
http://bugzilla.ximian.com/show_bug.cgi?id=52607
--- shadow/52607 2004-01-05 11:29:03.000000000 -0500
+++ shadow/52607.tmp.4541 2004-01-05 11:29:03.000000000 -0500
@@ -0,0 +1,94 @@
+Bug#: 52607
+Product: Mono/Class Libraries
+Version: unspecified
+OS:
+OS Details:
+Status: NEW
+Resolution:
+Severity:
+Priority: Blocker
+Component: System.XML
+AssignedTo: mono-bugs@ximian.com
+ReportedBy: mordechait@mainsoft.com
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: enum serialization is not fully compatibly with Microsoft.
+
+Description of Problem:
+Enum serialization (to a file for example) is not readable by Micorsoft VS
+2003 clients when using the namespace attribute (XmlTypeAttribute) attached
+to that enum.
+
+
+Steps to reproduce the problem:
+1. Write some console application that serialize some enum into a file.
+the enum must have a custom attibute:
+System.Xml.Serialization.XmlTypeAttribute(Namespace="something...")]
+2. run the program using MONO.
+3. Write some console application that reads this file and construct the
+object . Run it under Visual Studio , not Mono.
+
+Actual Results:
+an exception sample:
+System.InvalidOperationException error:There is an error in XML document
+(2, 2).
+ at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader
+xmlReader, String encodingStyle)
+ at System.Xml.Serialization.XmlSerializer.Deserialize(TextReader textReader)
+....
+
+
+Expected Results:
+successful deserializing.
+
+How often does this happen?
+always.
+
+
+Additional Information:
+Lets take an example when we have an enum:
+[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://www.webserviceX.NET/")]
+public enum Powers {ergsPersec,milliwatts,watts,}
+
+The problem in MONO is that the output of the serialization is:
+<?xml version="1.0" encoding="utf-8"?>
+<Powers xmlns="http://www.webserviceX.NET/">kilowatts</Powers>
+
+And Microsoft's output is always :
+<?xml version="1.0" encoding="utf-8"?>
+<Powers>kilowatts</Powers>
+
+Therefore, when de-serializing the output - MONO fails.
+
+I have a fix :
+where : XmlSerializationWriterInterpreter.cs line:111 in method:
+protected virtual void WriteObject (XmlTypeMapping typeMap, object ob,
+string element, string namesp, bool isNullable, bool needType, bool
+writeWrappingElem)
+
+in the section where:
+if (writeWrappingElem)
+{
+ if (map != typeMap || _format == SerializationFormat.Encoded)
+ needType = true;
+ WriteStartElement (element, namesp, ob); <------------- BUG BUG !
+}
+
+this section is buggy since in case of an enum you sould set namesp=""
+(empty string)
+
+therefore the fix is to add a small switch case.
+// Mordechai: In Microsoft they drop the namespace printout of an enum type
+// even if the user added the attribute
+// XmlTypeAttribute(Namespace="http://www.XXX.NET/").
+// It is completely ignored. therefore, I send empty string instead of the
+// real ns .
+// Additional fix may be to change XmlTypeMapping ctor so in case of enum
+// it will set this.ns="";
+switch (map.TypeData.SchemaType)
+{
+ case SchemaTypes.Enum: WriteStartElement (element, "", ob); break;
+ default: WriteStartElement (element, namesp, ob);break;
+}