I have a class generated by the xsd.exe tool. It doesn't matter what class, the same problem occurs always which is that every attribute having a type other than string is being ignored when the object is being serialized.
Deserializing the xml generated by the serialize method generates a valid .NET object having all attributes with type other than string are empty (int, bool, etc.)
I tried modifying the xml, adding the attributes and deserializing again. This seemed to work.
Edit: I have just created a demo schema and generated a C# class using the xsd tool. My schema looks as following:
<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns="http://PwC.C2C.Schemas.Internal.Schema1" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" targetNamespace="http://PwC.C2C.Schemas.Internal.Schema1" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Root">
<xs:complexType>
<xs:sequence>
<xs:element name="TestElement1">
<xs:complexType>
<xs:attribute name="AttributeBool" type="xs:boolean" />
<xs:attribute name="AttributeString" type="xs:string" />
<xs:attribute name="AttributeInt" type="xs:int" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
And the generated C# class looks like this:
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.6.1055.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://PwC.C2C.Schemas.Internal.Schema1")] [System.Xml.Serialization.XmlRootAttribute(Namespace="http://PwC.C2C.Schemas.Internal.Schema1", IsNullable=false)]
public partial class Root {
private RootTestElement1 testElement1Field;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public RootTestElement1 TestElement1 {
get {
return this.testElement1Field;
}
set {
this.testElement1Field = value;
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.6.1055.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://PwC.C2C.Schemas.Internal.Schema1")]
public partial class RootTestElement1 {
private bool attributeBoolField;
private bool attributeBoolFieldSpecified;
private string attributeStringField;
private int attributeIntField;
private bool attributeIntFieldSpecified;
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public bool AttributeBool {
get {
return this.attributeBoolField;
}
set {
this.attributeBoolField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool AttributeBoolSpecified {
get {
return this.attributeBoolFieldSpecified;
}
set {
this.attributeBoolFieldSpecified = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string AttributeString {
get {
return this.attributeStringField;
}
set {
this.attributeStringField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public int AttributeInt {
get {
return this.attributeIntField;
}
set {
this.attributeIntField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool AttributeIntSpecified {
get {
return this.attributeIntFieldSpecified;
}
set {
this.attributeIntFieldSpecified = value;
}
}
}
Interesting are the extra properties added if the specified type of the attribute in the schema is no string. attributeIntFieldSpecified and attributeBoolFieldSpecified.
These cause the attributes to be ignored when serializing the class and they need to be completely removed or set to true.