[Mono-bugs] [Bug 497293] New: XmlSerializer & xsd generated classes do not handle derived classes inside an xs:choice

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Wed Apr 22 10:26:54 EDT 2009


http://bugzilla.novell.com/show_bug.cgi?id=497293


           Summary: XmlSerializer & xsd generated classes do not handle
                    derived classes inside an xs:choice
    Classification: Mono
           Product: Mono: Class Libraries
           Version: 2.4.x
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: Sys.XML
        AssignedTo: atsushi at ximian.com
        ReportedBy: jkovach at arl.army.mil
         QAContact: mono-bugs at lists.ximian.com
          Found By: Community User


Created an attachment (id=287477)
 --> (http://bugzilla.novell.com/attachment.cgi?id=287477)
test program & schema

Description of Problem:
If you have an XML schema containing multiple base and derived types (where a
"derived type" is a xs:complexType that uses xs:extension to extend another
xs:complexType) and an element containing an xs:choice , and then use the xsd
tool to generate classes from this XML schema, the resulting generated classes
do not serialize in certain cases when the derived types are used (difficult to
explain clearly so please see the attached test case.)

The attached test case works correctly in Microsoft's .NET (3.5) but throws an
exception with mono.

Steps to reproduce the problem:
1. extract attached zip
2. xsd testxsd.xsd /classes /n:XsdInheritanceTest
3. gmcs test.cs testxsd.cs
4. mono test.exe

Actual Results:
[arl at vm5 XsdInheritanceTest]$ xsd testxsd.xsd /classes /n:XsdInheritanceTest
Written file ./testxsd.cs
[arl at vm5 XsdInheritanceTest]$ gmcs test.cs testxsd.cs
[arl at vm5 XsdInheritanceTest]$ mono test.exe

Unhandled Exception: System.InvalidOperationException: There was an error
generating the XML document. ---> System.InvalidOperationException: The type
XsdInheritanceTest.DerivedType1A may not be used in this context.
  at
System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteListContent
(System.Object container, System.Xml.Serialization.TypeData listType,
System.Xml.Serialization.ListMap map, System.Object ob,
System.Text.StringBuilder targetString) [0x00000] 
  at
System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteElementMembers
(System.Xml.Serialization.ClassMap map, System.Object ob, Boolean isValueList)
[0x00000] 
  at
System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteObjectElementElements
(System.Xml.Serialization.XmlTypeMapping typeMap, System.Object ob) [0x00000] 
  at
System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteObjectElement
(System.Xml.Serialization.XmlTypeMapping typeMap, System.Object ob,
System.String element, System.String namesp) [0x00000] 
  at System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteObject
(System.Xml.Serialization.XmlTypeMapping typeMap, System.Object ob,
System.String element, System.String namesp, Boolean isNullable, Boolean
needType, Boolean writeWrappingElem) [0x00000] 
  at System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteRoot
(System.Object ob) [0x00000] 
  at System.Xml.Serialization.XmlSerializer.Serialize (System.Object o,
System.Xml.Serialization.XmlSerializationWriter writer) [0x00000] 
  at System.Xml.Serialization.XmlSerializer.Serialize (System.Xml.XmlWriter
writer, System.Object o, System.Xml.Serialization.XmlSerializerNamespaces
namespaces) [0x00000] 
  --- End of inner exception stack trace ---
  at System.Xml.Serialization.XmlSerializer.Serialize (System.Xml.XmlWriter
writer, System.Object o, System.Xml.Serialization.XmlSerializerNamespaces
namespaces) [0x00000] 
  at System.Xml.Serialization.XmlSerializer.Serialize (System.IO.Stream stream,
System.Object o) [0x00000] 
  at XsdInheritanceTest.Program.Main (System.String[] args) [0x00000] 


Expected Results: (this is what Microsoft .NET does)
C:\Experimental\XsdInheritanceTest>xsd testxsd.xsd /classes
/n:XsdInheritanceTest
Microsoft (R) Xml Schemas/DataTypes support utility
[Microsoft (R) .NET Framework, Version 2.0.50727.3038]
Copyright (C) Microsoft Corporation. All rights reserved.
Writing file 'C:\Experimental\XsdInheritanceTest\testxsd.cs'.

C:\Experimental\XsdInheritanceTest>csc test.cs testxsd.cs
Microsoft (R) Visual C# 2008 Compiler version 3.5.30729.1
for Microsoft (R) .NET Framework version 3.5
Copyright (C) Microsoft Corporation. All rights reserved.


C:\Experimental\XsdInheritanceTest>test.exe
<?xml version="1.0"?>
<Message xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http:/
/www.w3.org/2001/XMLSchema" xmlns="test:testxsd.xsd">
  <Data1 xsi:type="DerivedType1A">
    <Stuff>foo</Stuff>
    <MoreStuff>bar</MoreStuff>
  </Data1>
  <Data2>
    <OtherStuff>baz</OtherStuff>
  </Data2>
</Message>


How often does this happen? Consistently

-- 
Configure bugmail: http://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.


More information about the mono-bugs mailing list