.NET XML API pundit, Daniel Cazzulino, has brought to light a bug in the way the Whidbey version of the XmlSerializer works with respect to fixed attribute values. If you used fixed values and expect them to be emmitted correctly to the instance document, I suggest you go vote this bug up.
That said, I think I understand why they don’t emit it. When you define a default value attribute in an XML Schema, it’s pretty much like saying: “If an instance document does not specify an explicit value for this attribute, this is the value that people interpreting the instance document should use instead.” Fixed is basically the same thing, except they can’t change the value at all. They can include it in the document, which is what Daniel is looking for here, but they cannot change the value. So, based on this logic, what the XmlSerializer is doing is saying: “Hey, this is the default/fixed value for the attribute, why should I pollute the instance document by stating the obvious when the person interpreting the document already knows what the value should be if I leave it out?”.
Ok, I somehow completely missed an important part of Daniel’s post so I need to correct myself. The part I missed is the all important use=”required” setting on the attribute that Daniel clearly pointed out in his post. How I missed it is beyond me, but obviously with that attribute in place the XmlSerializer is completely in the wrong for not outputting it. Thanks to Sam for pointing this out to me, I appreciate it.