By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,266 Members | 1,862 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,266 IT Pros & Developers. It's quick & easy.

XmlSerialzer error when multiple nillable elements of userdefined

P: n/a
Hi i am getting the following error while using XMLSerializer
XmlSerializer ser = new XmlSerializer(typeof(Person));

ERROR:
Unable to generate a temporary class (result=1).
error CS0266: Cannot implicitly convert type 'XSD.BiodataGender?' to
'XSD.BiodataRace?'. An explicit conversion exists (are you missing a cast?)

I am getting the above error when my xsd has multiple nillable elements of
userdefined type. If I change the type of either race or gender to String i
am getting any error. temporary class is generated easily

MY XSD :
<?xml version="1.0" encoding="UTF-8" ?>
<xsd:schema targetNamespace="http://my/ex" xmlns:version1="http://my/ex"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="person" type="version1:Person" />
<xsd:complexType name="Person">
<xsd:sequence>
<xsd:element name="biodata" type="version1:Biodata" minOccurs="1"
maxOccurs="1" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="Biodata">
<xsd:sequence>
<xsd:element name="gender" nillable="true">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="M" />
<xsd:enumeration value="F" />
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name="race" nillable="true">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="AI" />
<xsd:enumeration value="AS" />
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>

Code Generated by xsd.exe:

namespace XSD
{

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("cx sc", "0.57.0.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("c ode")]
[System.Xml.Serialization.XmlTypeAttribute(Namespac e="http://my/ex")]
[System.Xml.Serialization.XmlRootAttribute("person" ,
Namespace="http://my/ex", IsNullable=false)]
public partial class Person
{
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form= System.Xml.Schema.XmlSchemaForm.Unqualified)]
public Biodata biodata;
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("cx sc", "0.57.0.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("c ode")]
[System.Xml.Serialization.XmlTypeAttribute(Namespac e="http://my/ex")]
public partial class Biodata
{
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form= System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable=true)]
public System.Nullable<BiodataGendergender;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form= System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable=true)]
public System.Nullable<BiodataRacerace;
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("cx sc", "0.57.0.0")]
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(Anonymou sType=true,
Namespace="http://my/ex")]
public enum BiodataGender
{
/// <remarks/>
M,
/// <remarks/>
F,
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("cx sc", "0.57.0.0")]
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(Anonymou sType=true,
Namespace="http://my/ex")]
public enum BiodataRace
{
/// <remarks/>
AI,
/// <remarks/>
AS,
}
}
Nov 9 '07 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.