[Mono-bugs] [Bug 52906][Nor] New - XmlElementAttribute.IsNullable=true shouldn't work with value types.

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Thu, 15 Jan 2004 12:05:07 -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=52906

--- shadow/52906	2004-01-15 12:05:07.000000000 -0500
+++ shadow/52906.tmp.29861	2004-01-15 12:05:07.000000000 -0500
@@ -0,0 +1,104 @@
+Bug#: 52906
+Product: Mono/Class Libraries
+Version: unspecified
+OS: All
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: Sys.XML
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: erezl@mainsoft.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Summary: XmlElementAttribute.IsNullable=true shouldn't work with value types.
+
+Please fill in this template when reporting a bug, unless you know what 
+you are doing.
+Description of Problem:
+When Applying XmlElementAttribute with IsNullable property set to true on 
+a member which is a value type, the creation of the Xmlserializer for 
+that type should fail with an exception.
+In mono it doesn't, and the type is serialized to xml although it 
+shouldn't have.
+
+Steps to reproduce the problem:
+1. Compile and run the following code sample:
+public class intTest1
+{
+	[XmlElement(IsNullable=true)]
+	public int int1;
+}
+public class Test
+{
+	static void Main(string[] args)
+	{
+        	XmlSerializer serializer = new XmlSerializer(typeof
+(intTest1));
+		object o;
+		o = new sbyteTest1();
+		System.IO.StreamWriter sout = new System.IO.StreamWriter
+(@"../../" + o.GetType().ToString() + ".xml");
+		serializer.Serialize(sout, o);
+		sout.Close();
+	}
+}
+
+Actual Results:
+1). No exception is thrown, The object is serialized.
+
+Expected Results:
+1). In .NET i get an unhandled System.InvalidOperationException at 
+XmlSerializer serializer = new XmlSerializer(typeof(intTest1));
+
+Unhandled Exception: System.InvalidOperationException: There was an error 
+reflec
+ting type 'sbyteTest1'. ---> System.InvalidOperationException: There was 
+an erro
+r reflecting field 'sbyte1'. ---> System.InvalidOperationException: 
+IsNullable m
+ay not be 'true' for value type System.SByte.
+   at System.Xml.Serialization.XmlReflectionImporter.CheckNullable
+(Boolean isNul
+lable, TypeDesc typeDesc)
+   at System.Xml.Serialization.XmlReflectionImporter.ImportAccessorMapping
+(Membe
+rMapping accessor, FieldModel model, XmlAttributes a, String ns, Type 
+choiceIden
+tifierType)
+   at System.Xml.Serialization.XmlReflectionImporter.ImportFieldMapping
+(StructMo
+del parent, FieldModel model, XmlAttributes a, String ns)
+   at 
+System.Xml.Serialization.XmlReflectionImporter.ImportStructLikeMapping(Str
+uctModel model, String ns)
+   --- End of inner exception stack trace ---
+   at 
+System.Xml.Serialization.XmlReflectionImporter.ImportStructLikeMapping(Str
+uctModel model, String ns)
+   at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping
+(TypeModel
+ model, String ns, ImportContext context, String dataType, Boolean 
+repeats)
+   --- End of inner exception stack trace ---
+   at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping
+(TypeModel
+ model, String ns, ImportContext context, String dataType, Boolean 
+repeats)
+   at System.Xml.Serialization.XmlReflectionImporter.ImportElement
+(TypeModel mod
+el, XmlRootAttribute root, String defaultNamespace)
+   at System.Xml.Serialization.XmlSerializer..ctor(Type type, String 
+defaultName
+space)
+   at System.Xml.Serialization.XmlSerializer..ctor(Type type)
+   at Test.Main(String[] args) in c:\temp\testdeserializer\test.cs:line
+17
+
+How often does this happen? 
+Always.
+
+Additional Information:
+This happens with all value types including Enums and structs.