(Type your message here)
--------------------------------
From: keith bannister
Hi,
I'm new to .net (as of last week) but here goes.
I want to serialize/deserialize a file the conforms to an XML schema (xsd).
I've got the schema & I used the xsd utility to create the class (xsd.exe /c properties.xsd /n:somenamespace ). it compiles without a hitch (xsd does a good job of puting '@' around the keyword clashes)
When I do XmlSerializer ser = new XmlSerializer(typeof(properties)) I get the standard FileNotFound exception that everyone gets when the DOM compiler fails.
The XmlSerializerPreCompiler utility, it tells me the following:
c:\Temp\_utcyjot.0.cs(269,72): error CS0030: Cannot convert type 'somenamespace.simpleref[]' to 'somenamespace.simpleref'
c:\Temp\_utcyjot.0.cs(570,64): error CS0030: Cannot convert type 'somenamespace.simpleref[]' to 'somenamespace.simpleref'
c:\Temp\_utcyjot.0.cs(1087,185): error CS0029: Cannot implicitly convert type 'somenamespace.simpleref' to 'somenamespace.simpleref[]'
c:\Temp\_utcyjot.0.cs(1632,189): error CS0029: Cannot implicitly convert type 'somenamespace.simpleref' to 'somenamespace.simpleref[]'
Basically it looks like 'xsd.exe' somehow generates a class the XmlSerializer can't handle. It looks like either xsd or XmlSerializer has a problem with some arrays somewhere. Is this a microsoft bug, or have I done something wrong?
Is a bit of a shame, really.
Any ideas?
Bits attached.
---------------------------
XSD FILE
---------------------------
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="properties">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" ref="description" />
<xs:choice maxOccurs="unbounded">
<xs:element ref="simple" />
<xs:element ref="simplesequence" />
<xs:element ref="test" />
<xs:element ref="struct" />
<xs:element ref="structsequence" />
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="simple">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" ref="description" />
<xs:element minOccurs="0" ref="value" />
<xs:element minOccurs="0" ref="units" />
<xs:element minOccurs="0" ref="range" />
<xs:element minOccurs="0" ref="enumerations" />
<xs:element minOccurs="0" maxOccurs="unbounded" ref="kind" />
<xs:element minOccurs="0" ref="action" />
</xs:sequence>
<xs:attribute name="id" type="xs:ID" use="required" />
<xs:attribute name="type" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="boolean" />
<xs:enumeration value="char" />
<xs:enumeration value="double" />
<xs:enumeration value="float" />
<xs:enumeration value="short" />
<xs:enumeration value="long" />
<xs:enumeration value="objref" />
<xs:enumeration value="octet" />
<xs:enumeration value="string" />
<xs:enumeration value="ulong" />
<xs:enumeration value="ushort" />
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="name" type="xs:string" />
<xs:attribute name="mode" default="readwrite">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="readonly" />
<xs:enumeration value="readwrite" />
<xs:enumeration value="writeonly" />
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name="description" type="xs:string" />
<xs:element name="value" type="xs:string" />
<xs:element name="units" type="xs:string" />
<xs:element name="range">
<xs:complexType>
<xs:attribute name="min" type="xs:string" use="required" />
<xs:attribute name="max" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
<xs:element name="enumerations">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" ref="enumeration" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="enumeration">
<xs:complexType>
<xs:attribute name="label" type="xs:string" use="required" />
<xs:attribute name="value" type="xs:string" />
</xs:complexType>
</xs:element>
<xs:element name="kind">
<xs:complexType>
<xs:attribute name="kindtype" default="configure">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="allocation" />
<xs:enumeration value="configure" />
<xs:enumeration value="test" />
<xs:enumeration value="execparam" />
<xs:enumeration value="factoryparam" />
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name="action">
<xs:complexType>
<xs:attribute name="type" default="external">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="eq" />
<xs:enumeration value="ne" />
<xs:enumeration value="gt" />
<xs:enumeration value="lt" />
<xs:enumeration value="ge" />
<xs:enumeration value="le" />
<xs:enumeration value="external" />
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name="simplesequence">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" ref="description" />
<xs:element minOccurs="0" ref="values" />
<xs:element minOccurs="0" ref="units" />
<xs:element minOccurs="0" ref="range" />
<xs:element minOccurs="0" maxOccurs="unbounded" ref="kind" />
<xs:element minOccurs="0" ref="action" />
</xs:sequence>
<xs:attribute name="id" type="xs:ID" use="required" />
<xs:attribute name="type" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="boolean" />
<xs:enumeration value="char" />
<xs:enumeration value="double" />
<xs:enumeration value="float" />
<xs:enumeration value="short" />
<xs:enumeration value="long" />
<xs:enumeration value="objref" />
<xs:enumeration value="octet" />
<xs:enumeration value="string" />
<xs:enumeration value="ulong" />
<xs:enumeration value="ushort" />
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="name" type="xs:string" />
<xs:attribute name="mode" default="readwrite">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="readonly" />
<xs:enumeration value="readwrite" />
<xs:enumeration value="writeonly" />
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name="values">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" ref="value" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="test">
<xs:complexType>
<xs:sequence>
<xs:element ref="description" />
<xs:element minOccurs="0" ref="inputvalue" />
<xs:element ref="resultvalue" />
</xs:sequence>
<xs:attribute name="id" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
<xs:element name="inputvalue">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" ref="simple" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="resultvalue">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" ref="simple" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="struct">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" ref="description" />
<xs:element maxOccurs="unbounded" ref="simple" />
<xs:element minOccurs="0" ref="configurationkind" />
</xs:sequence>
<xs:attribute name="id" type="xs:ID" use="required" />
<xs:attribute name="name" type="xs:string" />
<xs:attribute name="mode" default="readwrite">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="readonly" />
<xs:enumeration value="readwrite" />
<xs:enumeration value="writeonly" />
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name="configurationkind">
<xs:complexType>
<xs:attribute name="kindtype" default="configure">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="configure" />
<xs:enumeration value="factoryparam" />
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name="structsequence">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" ref="description" />
<xs:element maxOccurs="unbounded" ref="structvalue" />
<xs:element minOccurs="0" ref="configurationkind" />
</xs:sequence>
<xs:attribute name="id" type="xs:ID" use="required" />
<xs:attribute name="structrefid" type="xs:string" use="required" />
<xs:attribute name="name" type="xs:string" />
<xs:attribute name="mode" default="readwrite">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="readonly" />
<xs:enumeration value="readwrite" />
<xs:enumeration value="writeonly" />
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name="structvalue">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" ref="simpleref" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="simpleref">
<xs:complexType>
<xs:attribute name="refid" type="xs:string" use="required" />
<xs:attribute name="value" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
</xs:schema>
---------------------------
CLASS GENERATED BY XSD
---------------------------
//------------------------------------------------------------------------------
// <autogenerated>
// This code was generated by a tool.
// Runtime Version: 1.1.4322.573
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </autogenerated>
//------------------------------------------------------------------------------
//
// This source code was auto-generated by xsd, Version=1.1.4322.573.
//
namespace jvms.xmlimport.sca221prf {
using System.Xml.Serialization;
/// <remarks/>
[System.Xml.Serialization.XmlRootAttribute(Namespac e="", IsNullable=false)]
public class properties {
/// <remarks/>
public string description;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("stru ctsequence", typeof(structsequence))]
[System.Xml.Serialization.XmlElementAttribute("simp lesequence", typeof(simplesequence))]
[System.Xml.Serialization.XmlElementAttribute("simp le", typeof(simple))]
[System.Xml.Serialization.XmlElementAttribute("test ", typeof(test))]
[System.Xml.Serialization.XmlElementAttribute("stru ct", typeof(@struct))]
public object[] Items;
}
/// <remarks/>
[System.Xml.Serialization.XmlRootAttribute(Namespac e="", IsNullable=false)]
public class structsequence {
/// <remarks/>
public string description;
/// <remarks/>
[System.Xml.Serialization.XmlArrayItemAttribute(typ eof(simpleref), IsNullable=false)]
public simpleref[][] structvalue;
/// <remarks/>
public configurationkind configurationkind;
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute(Dat aType="ID")]
public string id;
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string structrefid;
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string name;
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
[System.ComponentModel.DefaultValueAttribute(struct sequenceMode.readwrite)]
public structsequenceMode mode = structsequenceMode.readwrite;
}
/// <remarks/>
[System.Xml.Serialization.XmlRootAttribute(Namespac e="", IsNullable=false)]
public class simpleref {
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string refid;
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string value;
}
/// <remarks/>
[System.Xml.Serialization.XmlRootAttribute(Namespac e="", IsNullable=false)]
public class configurationkind {
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
[System.ComponentModel.DefaultValueAttribute(config urationkindKindtype.configure)]
public configurationkindKindtype kindtype = configurationkindKindtype.configure;
}
/// <remarks/>
public enum configurationkindKindtype {
/// <remarks/>
configure,
/// <remarks/>
factoryparam,
}
/// <remarks/>
[System.Xml.Serialization.XmlRootAttribute(Namespac e="", IsNullable=false)]
public class @struct {
/// <remarks/>
public string description;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("simp le")]
public simple[] simple;
/// <remarks/>
public configurationkind configurationkind;
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute(Dat aType="ID")]
public string id;
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string name;
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
[System.ComponentModel.DefaultValueAttribute(struct Mode.readwrite)]
public structMode mode = structMode.readwrite;
}
/// <remarks/>
[System.Xml.Serialization.XmlRootAttribute(Namespac e="", IsNullable=false)]
public class simple {
/// <remarks/>
public string description;
/// <remarks/>
public string value;
/// <remarks/>
public string units;
/// <remarks/>
public range range;
/// <remarks/>
[System.Xml.Serialization.XmlArrayItemAttribute(IsN ullable=false)]
public enumeration[] enumerations;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("kind ")]
public kind[] kind;
/// <remarks/>
public action action;
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute(Dat aType="ID")]
public string id;
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public simpleType type;
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string name;
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
[System.ComponentModel.DefaultValueAttribute(simple Mode.readwrite)]
public simpleMode mode = simpleMode.readwrite;
}
/// <remarks/>
[System.Xml.Serialization.XmlRootAttribute(Namespac e="", IsNullable=false)]
public class range {
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string min;
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string max;
}
/// <remarks/>
[System.Xml.Serialization.XmlRootAttribute(Namespac e="", IsNullable=false)]
public class enumeration {
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string label;
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string value;
}
/// <remarks/>
[System.Xml.Serialization.XmlRootAttribute(Namespac e="", IsNullable=false)]
public class kind {
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
[System.ComponentModel.DefaultValueAttribute(kindKi ndtype.configure)]
public kindKindtype kindtype = kindKindtype.configure;
}
/// <remarks/>
public enum kindKindtype {
/// <remarks/>
allocation,
/// <remarks/>
configure,
/// <remarks/>
test,
/// <remarks/>
execparam,
/// <remarks/>
factoryparam,
}
/// <remarks/>
[System.Xml.Serialization.XmlRootAttribute(Namespac e="", IsNullable=false)]
public class action {
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
[System.ComponentModel.DefaultValueAttribute(action Type.external)]
public actionType type = actionType.external;
}
/// <remarks/>
public enum actionType {
/// <remarks/>
eq,
/// <remarks/>
ne,
/// <remarks/>
gt,
/// <remarks/>
lt,
/// <remarks/>
ge,
/// <remarks/>
le,
/// <remarks/>
external,
}
/// <remarks/>
public enum simpleType {
/// <remarks/>
boolean,
/// <remarks/>
@char,
/// <remarks/>
@double,
/// <remarks/>
@float,
/// <remarks/>
@short,
/// <remarks/>
@long,
/// <remarks/>
objref,
/// <remarks/>
octet,
/// <remarks/>
@string,
/// <remarks/>
@ulong,
/// <remarks/>
@ushort,
}
/// <remarks/>
public enum simpleMode {
/// <remarks/>
@readonly,
/// <remarks/>
readwrite,
/// <remarks/>
writeonly,
}
/// <remarks/>
public enum structMode {
/// <remarks/>
@readonly,
/// <remarks/>
readwrite,
/// <remarks/>
writeonly,
}
/// <remarks/>
[System.Xml.Serialization.XmlRootAttribute(Namespac e="", IsNullable=false)]
public class test {
/// <remarks/>
public string description;
/// <remarks/>
[System.Xml.Serialization.XmlArrayItemAttribute(IsN ullable=false)]
public simple[] inputvalue;
/// <remarks/>
[System.Xml.Serialization.XmlArrayItemAttribute(IsN ullable=false)]
public simple[] resultvalue;
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string id;
}
/// <remarks/>
[System.Xml.Serialization.XmlRootAttribute(Namespac e="", IsNullable=false)]
public class simplesequence {
/// <remarks/>
public string description;
/// <remarks/>
[System.Xml.Serialization.XmlArrayItemAttribute("va lue", IsNullable=false)]
public string[] values;
/// <remarks/>
public string units;
/// <remarks/>
public range range;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("kind ")]
public kind[] kind;
/// <remarks/>
public action action;
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute(Dat aType="ID")]
public string id;
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public simplesequenceType type;
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string name;
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
[System.ComponentModel.DefaultValueAttribute(simple sequenceMode.readwrite)]
public simplesequenceMode mode = simplesequenceMode.readwrite;
}
/// <remarks/>
public enum simplesequenceType {
/// <remarks/>
boolean,
/// <remarks/>
@char,
/// <remarks/>
@double,
/// <remarks/>
@float,
/// <remarks/>
@short,
/// <remarks/>
@long,
/// <remarks/>
objref,
/// <remarks/>
octet,
/// <remarks/>
@string,
/// <remarks/>
@ulong,
/// <remarks/>
@ushort,
}
/// <remarks/>
public enum simplesequenceMode {
/// <remarks/>
@readonly,
/// <remarks/>
readwrite,
/// <remarks/>
writeonly,
}
/// <remarks/>
public enum structsequenceMode {
/// <remarks/>
@readonly,
/// <remarks/>
readwrite,
/// <remarks/>
writeonly,
}
/// <remarks/>
[System.Xml.Serialization.XmlRootAttribute(Namespac e="", IsNullable=false)]
public class enumerations {
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("enum eration")]
public enumeration[] enumeration;
}
/// <remarks/>
[System.Xml.Serialization.XmlRootAttribute(Namespac e="", IsNullable=false)]
public class values {
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("valu e")]
public string[] value;
}
/// <remarks/>
[System.Xml.Serialization.XmlRootAttribute(Namespac e="", IsNullable=false)]
public class inputvalue {
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("simp le")]
public simple[] simple;
}
/// <remarks/>
[System.Xml.Serialization.XmlRootAttribute(Namespac e="", IsNullable=false)]
public class resultvalue {
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("simp le")]
public simple[] simple;
}
/// <remarks/>
[System.Xml.Serialization.XmlRootAttribute(Namespac e="", IsNullable=false)]
public class structvalue {
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("simp leref")]
public simpleref[] simpleref;
}
}
-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)
<Id>ChwO0pC3l06c8AS8TP67Zw==</Id>