HighTechTalks DotNet Forums  

XmlSerialzer error when multiple nillable elements of userdefined

Dotnet XML microsoft.public.dotnet.xml


Discuss XmlSerialzer error when multiple nillable elements of userdefined in the Dotnet XML forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
krishna
 
Posts: n/a

Default XmlSerialzer error when multiple nillable elements of userdefined - 11-09-2007 , 02:04 PM






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<BiodataGender> gender;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form= System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable=true)]
public System.Nullable<BiodataRace> race;
}
/// <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,
}
}



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.