Value type with no default value or accompanying boolean field.
Result: minOccurs value of output element is set to 1
Reference type with an XmlElement attribute's IsNullable property set to true.
Result: minOccurs value of output element is set to 1. In the element, the nillable attribute is also set to true.
A property of type string (unfortunately) always has a default value of
string.Empty
so it cannot ever have a null default value. This means we can't ever satisfy the first solution. The only way to generate a MinOccurs=1 for strings is to make the element nullable:
[XmlElementAttribute(IsNullable = true)] public string Item { ... }
<XmlElement(IsNullable:=True)> Public Item As String
Thanks for the info guys ... I ran into the same problem were I want to make a string mandatory ... But I can't :-(