0

I have an XSD with the following type defined:

<xs:complexType name="AttributeValue">
    <xs:simpleContent>
        <xs:extension base="xs:string">
            <xs:attribute name="type"
                type="ns:MyType" 
                default="Value"/>

I would like to write a C# object created via the XSD.exe out via the XmlSerializer with one of these attributeValue types. Is it possible to force the serializer to write out the type attribute even when it is equal to the default?

Note that I cannot modify the XSD and I'd like to avoid modifying the C# POCO generated via XSD.exe as this will change in the future and I'd like to avoid the maintenance overhead.

Spence
  • 28,526
  • 15
  • 68
  • 103

1 Answers1

1

This is by-design. Here is the reply from MS. Suggested workaround is to comment out/remove the System.ComponentModel.DefaultValueAttribute for the attribute field. The KB article says that "Microsoft plans to change this behavior in the next major version release of the .NET Framework.", but it looks like they didn't.

Jiaji Wu
  • 459
  • 3
  • 10
  • I liked the support reference from M$. Just in case someone has a ninja answer, I'm not going to mark this correct just yet. But I think I'm out of luck. – Spence Apr 26 '12 at 11:23