"Jeff T." <yofnik@comcast.net> wrote in message
news:1117044035.249323.209230@o13g2000cwo.googlegroups.com...
> I am noticing some VERY odd behavior when serializing and deserializing
> classes that were generate using the XSD.exe utility. Can anyone
> confirm if this is a bug (or it I am just doing something I shouldn't!)
>
> Basically what is happening is that if the schema contains a collection
> of base types and the base type contains the xs:anyAttribute type, the
> xsi:type attribute gets set twice for a single element. Here is an
> example of the erroneous output:
>
> <?xml version="1.0" encoding="utf-16"?>
> <BaseCollection ... xsi:type="DerivedTypeCollection" >
> <Collection>
> <BaseTypes xsi:type="DerivedType1" d3p1:attr1="test1"
> xsi:type="DerivedType1" d3p1:attr3="test3"
> xmlns:d3p1="
http://www.myns.com/bugtest" />
> <BaseTypes xsi:type="DerivedType2" d3p1:attr1="test2"
> xsi:type="DerivedType2" d3p1:attr2="test4"
> xmlns:d3p1="
http://www.myns.com/bugtest" />
> </Collection>
> </BaseCollection>
>
> Notice that BaseTypes elements have TWO attributes for xsi:type!!!!!
> This causes serialization to fail.
>
> This occurs when I have XML data, deserialize it to an object
> (generated by xsd.exe), and then serialize it back to XML again.
>
> The schema for the above XML looks like:
> <xs:complexType name="BaseType">
> <xs:sequence></xs:sequence>
> <xs:attribute name="attr1" type="xs:string" use="required"/>
> <xs:anyAttribute /> <----------THIS CAUSES THE BUG
> </xs:complexType>
>
> <xs:complexType name="DerivedType1">
> <xs:complexContent>
> <xs:extension base="BaseType">
> <xs:sequence></xs:sequence>
> <xs:attribute name="attr3" type="xs:string" />
> </xs:extension>
> </xs:complexContent>
> </xs:complexType>
>
> I can remove the anyAttribute for now, but I wanted in there originally
> for flexibility. Is this a bug with XmlSerializer?
>
> Thanks,
> Jeff
>