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

XmlSerializer constructor fails with xsd.exe generated class

P: n/a
I'm new to .net so here goes.

I'm tying to deserialize a class that is associated with an XML
schema.

I created the C# class with xsd.exe as below:

xsd.exe /c /n:somenamespace properties.xsd

this creates properties.cs

When I do
XmlSerializer s = new XmlSerializer(typeof(somenamespace.properties));

I get the standard exception everyone gets when the DOM compiler fails
("File or assembly name
_utcyjot.0.dll, or one of its dependencies, was not found") (I copied
the dll name from below)

Using Chris Sells' XmlSerializerPreCompiler tools gives me the
following errors:

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[]'

It appears as though xsd.exe has created a class that crashes
XmlSerializer. Unless I've done something wrong.

Can anyone reproduce this? How do I give you my .net environment
string? Does anyone know a fix/workaround? Have I done something
wrong? Is my xsd too complex for XmlSerializer or xsd.exe?

Any response always deeply appreciated.

Cheers,

keith

------------------------------
properties.xsd - the schema 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>

----------------------------
properties.cs generated by xsd.exe
-----------------------------
//------------------------------------------------------------------------------
// <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;
}
}
Nov 12 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Hi Keith,

Did you get an answer to your question you posted on the online .net
forum on Sep 02, 2004.

I ran into the same problem and would like to know.

Thanks

Andy

Nov 12 '05 #2

P: n/a
Hi Andy,

I've had no replies to this at all, and not been able to solve it.

I was hoping either a Microsoft guy would acknowledge it as a bug, or
someone would tell me what I've done wrong. Neither has happened.

I found something somewhere, perhaps on this newsgroup, posted by a
Micrsoft developer who said XmlSerializer/Xsd.exe would crash when using
complex schema, or jagged arrays. I don't think I've got jagged arrays,
and I didn't think my schema was all that complex.

It seems like it's a known issue in Microsoft (dunno if it's in
KnowledgeBase).

It'd be nice if you could do something like:

try {
doComplexCompliledWay();
} catch (CompilerException compilerBug) {
logToMicrosoft(compilerBug);
doSlowButReliableWay();
}

But alas no.

I've basically given up on the project, but would like to start it up
again if I can get around this bug.

This was my first C# application. It was a bit disappointing to have it
die this early.

Anyway, let me know if you find anything out.

Cheers,

keith
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #3

P: n/a
Keith,

One hack is to remove the "maxoccurs" associated with the field in the
schema. This will get you past the problem.

But, I could only do this because I wasn't using those fields in the
schema I am using (ACORD).

Nov 12 '05 #4

P: n/a
Thanks for that! The xsd is actually automatically generated from a dtd,
so I can probably get rid of that field. I'll have a go when I get a
spare second (a few weeks at best, I'm afraid) and get back to see if it
works.

Cheers!

Keith

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #5

P: n/a
Thanks Vitaleaf! :D I was having the same problem, and taking out the
maxOccurs attribute it works! The difference is that I'm using the
troubled element (is a collection of stock prices).

I came here through google, and I find the answer I was looking for
one week, thank guys!

Greets from Argentina

Nov 12 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.