Maybe someone can explain to me why this:
using
System;
using System.Xml.Serialization;
public
class Foo {
[XmlAttribute]
[System.ComponentModel.DefaultValueAttribute("three")]
public string value = "three";
}
public
class App {
public static void Main() {
XmlSerializer ser = new XmlSerializer(typeof(Foo));
Foo foo = new Foo();
ser.Serialize(Console.Out, foo);
}
}
produces this:
<Foo />
whereas if you remove the DefaultValue attribute, you get this:
<Foo value=”three” />
which is what I would expect. This is particularly troubling, since wsdl.exe will generate proxies that use System.ComponentModel.DefaultValueAttribute when it sees schema types with fixed value constraints.
I have to assume this is a bug in System.Xml.Serialization, but I'm willing to believe that there's some subtlety I've missed. I've confirmed this behavior in CLR 1.1 and 2.0.40607.
Posted
Jul 27 2004, 08:15 PM
by
craig-andera