473,486 Members | 2,353 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

XmlSerializer fails to serialize xsd.exe generated classes

cd~
I can provide a test app, the news server won't allow me to post the files
because they are too large (93KB and 1.2KB)

I downloaded the ESRI ArcXml schema and generated the classes from the
schema using xsd.exe, which took a while because xsd doesn't handle
recursive elements very well (StackOverFlow exception during generation).
Now that I have the classes I am trying to serialize them to an xml document
to send to ArcIMS to generate map images. The .trc file is a text file that
contains the exception information that this throws.

This is the only document I am able to find on this bug on the web,
convieniently on MSDN:
http://msdn.microsoft.com/netframewo...xmlserial.aspx
The only solution that I can come up with is to install VS2003 and compile
the ArcXml classes since this seems to be something that has been broken in
VS2005

Thank you for your time,
Russell

Jan 27 '06 #1
8 5421
cd~
This is the test code that I am having trouble with, it fails on the first
line of the try block:

using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using ESRI.ArcIMS.Server;
using ESRI.ArcXml;
using System.Diagnostics;

namespace ArcXmlTest {
class Program {
private static ARCXML CreateImageRequest() {
ARCXML ax = new ARCXML();
REQUEST req = new REQUEST();
GET_IMAGE gi = new GET_IMAGE();

ax.Item = req;
req.Item = gi;
return ax;
}

private static XmlDocument Serialize<T>(T xmlObject) {
XmlSerializer xs = new
System.Xml.Serialization.XmlSerializer(typeof(T));
StringBuilder sb = new StringBuilder();

using (XmlWriter xw = XmlWriter.Create(sb)){
XmlDocument xml = new XmlDocument();
xs.Serialize(xw, xmlObject);
xml.LoadXml(sb.ToString());
return xml;
}
}

static void Main(string[] args) {
ARCXML arcxml = CreateImageRequest();
GET_IMAGE imageRequest = ((GET_IMAGE)((REQUEST)arcxml.Item).Item);
PROPERTIES props = new PROPERTIES();

imageRequest.Items = new object[] {props};
imageRequest.ItemsElementName = new ItemsChoiceType4[] {
ItemsChoiceType4.PROPERTIES };
props.Items = new object[]{new ENVELOPE()};

TextWriterTraceListener listener = new
TextWriterTraceListener(@"c:\ArcXmlTest.trc");
Trace.AutoFlush = true;
Trace.Listeners.Add(listener);

try {
Trace.WriteLine(Serialize<GET_IMAGE>(imageRequest) .OuterXml);
Trace.WriteLine(IMSConnection.Send(arcxml.Serializ e().OuterXml));
}
catch(System.Exception e){
Trace.WriteLine(e.ToString());
}
}
}
}

"cd~" <ra*****@community.nospam> wrote in message
news:uE*************@TK2MSFTNGP10.phx.gbl...
I can provide a test app, the news server won't allow me to post the files
because they are too large (93KB and 1.2KB)

I downloaded the ESRI ArcXml schema and generated the classes from the
schema using xsd.exe, which took a while because xsd doesn't handle
recursive elements very well (StackOverFlow exception during generation).
Now that I have the classes I am trying to serialize them to an xml
document
to send to ArcIMS to generate map images. The .trc file is a text file
that
contains the exception information that this throws.

This is the only document I am able to find on this bug on the web,
convieniently on MSDN:
http://msdn.microsoft.com/netframewo...xmlserial.aspx
The only solution that I can come up with is to install VS2003 and compile
the ArcXml classes since this seems to be something that has been broken
in
VS2005

Thank you for your time,
Russell


Jan 27 '06 #2
cd~
This is the exception generated:

System.InvalidOperationException: There was an error generating the XML
document. ---> System.InvalidOperationException: Value of ItemsElementName
mismatches the type of System.Object[]; you need to set it to
ESRI.ArcXml.ItemsChoiceType4.@PROPERTIES.
at
Microsoft.Xml.Serialization.GeneratedAssembly.XmlS erializationWriterGET_IMAGE.Write151_GET_IMAGE(Str ing
n, String ns, GET_IMAGE o, Boolean isNullable, Boolean needType)
at
Microsoft.Xml.Serialization.GeneratedAssembly.XmlS erializationWriterGET_IMAGE.Write152_GET_IMAGE(Obj ect
o)
--- End of inner exception stack trace ---
at System.Xml.Serialization.XmlSerializer.Serialize(X mlWriter xmlWriter,
Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String
id)
at System.Xml.Serialization.XmlSerializer.Serialize(X mlWriter xmlWriter,
Object o)
at ArcXmlTest.Program.Serialize[T](T xmlObject) in C:\Documents and
Settings\ralibey\My Documents\Visual Studio
2005\Projects\ArcXmlTest\ArcXmlTest\Program.cs:lin e 48
at ArcXmlTest.Program.Main(String[] args) in C:\Documents and
Settings\ralibey\My Documents\Visual Studio
2005\Projects\ArcXmlTest\ArcXmlTest\Program.cs:lin e 68

"cd~" <ra*****@community.nospam> wrote in message
news:u1**************@TK2MSFTNGP14.phx.gbl...
This is the test code that I am having trouble with, it fails on the first
line of the try block:

using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using ESRI.ArcIMS.Server;
using ESRI.ArcXml;
using System.Diagnostics;

namespace ArcXmlTest {
class Program {
private static ARCXML CreateImageRequest() {
ARCXML ax = new ARCXML();
REQUEST req = new REQUEST();
GET_IMAGE gi = new GET_IMAGE();

ax.Item = req;
req.Item = gi;
return ax;
}

private static XmlDocument Serialize<T>(T xmlObject) {
XmlSerializer xs = new
System.Xml.Serialization.XmlSerializer(typeof(T));
StringBuilder sb = new StringBuilder();

using (XmlWriter xw = XmlWriter.Create(sb)){
XmlDocument xml = new XmlDocument();
xs.Serialize(xw, xmlObject);
xml.LoadXml(sb.ToString());
return xml;
}
}

static void Main(string[] args) {
ARCXML arcxml = CreateImageRequest();
GET_IMAGE imageRequest = ((GET_IMAGE)((REQUEST)arcxml.Item).Item);
PROPERTIES props = new PROPERTIES();

imageRequest.Items = new object[] {props};
imageRequest.ItemsElementName = new ItemsChoiceType4[] {
ItemsChoiceType4.PROPERTIES };
props.Items = new object[]{new ENVELOPE()};

TextWriterTraceListener listener = new
TextWriterTraceListener(@"c:\ArcXmlTest.trc");
Trace.AutoFlush = true;
Trace.Listeners.Add(listener);

try {

Trace.WriteLine(Serialize<GET_IMAGE>(imageRequest) .OuterXml);

Trace.WriteLine(IMSConnection.Send(arcxml.Serializ e().OuterXml));
}
catch(System.Exception e){
Trace.WriteLine(e.ToString());
}
}
}
}

"cd~" <ra*****@community.nospam> wrote in message
news:uE*************@TK2MSFTNGP10.phx.gbl...
I can provide a test app, the news server won't allow me to post the files
because they are too large (93KB and 1.2KB)

I downloaded the ESRI ArcXml schema and generated the classes from the
schema using xsd.exe, which took a while because xsd doesn't handle
recursive elements very well (StackOverFlow exception during generation).
Now that I have the classes I am trying to serialize them to an xml
document
to send to ArcIMS to generate map images. The .trc file is a text file
that
contains the exception information that this throws.

This is the only document I am able to find on this bug on the web,
convieniently on MSDN:
http://msdn.microsoft.com/netframewo...xmlserial.aspx
The only solution that I can come up with is to install VS2003 and
compile
the ArcXml classes since this seems to be something that has been broken
in
VS2005

Thank you for your time,
Russell



Jan 27 '06 #3
Hi Russell,
Welcome to MSDN Newsgroup!
Currently I am looking for somebody who could help you on it. We will reply
here with more information as soon as possible. If you have any more
concerns on it, please feel free to post here.

Best Regards,

Terry Fei[MSFT]
Microsoft Community Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
From: "cd~" <ra*****@community.nospam>
References: <uE*************@TK2MSFTNGP10.phx.gbl> <u1**************@TK2MSFTNGP14.phx.gbl>Subject: Re: XmlSerializer fails to serialize xsd.exe generated classes
Date: Fri, 27 Jan 2006 09:30:44 -0600
Lines: 126
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
X-RFC2646: Format=Flowed; Response
Message-ID: <eG**************@TK2MSFTNGP09.phx.gbl>
Newsgroups: microsoft.public.dotnet.xml
NNTP-Posting-Host: dslstatic-236-168.ideaone.net 64.21.236.168
Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP09.phx.gbl
Xref: TK2MSFTNGXA02.phx.gbl microsoft.public.dotnet.xml:29672
X-Tomcat-NG: microsoft.public.dotnet.xml

This is the exception generated:

System.InvalidOperationException: There was an error generating the XML
document. ---> System.InvalidOperationException: Value of ItemsElementName
mismatches the type of System.Object[]; you need to set it to
ESRI.ArcXml.ItemsChoiceType4.@PROPERTIES.
at
Microsoft.Xml.Serialization.GeneratedAssembly.Xml SerializationWriterGET_IMA GE.Write151_GET_IMAGE(Stringn, String ns, GET_IMAGE o, Boolean isNullable, Boolean needType)
at
Microsoft.Xml.Serialization.GeneratedAssembly.Xml SerializationWriterGET_IMA GE.Write152_GET_IMAGE(Objecto)
--- End of inner exception stack trace ---
at System.Xml.Serialization.XmlSerializer.Serialize(X mlWriter xmlWriter,Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String
id)
at System.Xml.Serialization.XmlSerializer.Serialize(X mlWriter xmlWriter,Object o)
at ArcXmlTest.Program.Serialize[T](T xmlObject) in C:\Documents and
Settings\ralibey\My Documents\Visual Studio
2005\Projects\ArcXmlTest\ArcXmlTest\Program.cs:li ne 48
at ArcXmlTest.Program.Main(String[] args) in C:\Documents and
Settings\ralibey\My Documents\Visual Studio
2005\Projects\ArcXmlTest\ArcXmlTest\Program.cs:li ne 68

"cd~" <ra*****@community.nospam> wrote in message
news:u1**************@TK2MSFTNGP14.phx.gbl...
This is the test code that I am having trouble with, it fails on the first line of the try block:

using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using ESRI.ArcIMS.Server;
using ESRI.ArcXml;
using System.Diagnostics;

namespace ArcXmlTest {
class Program {
private static ARCXML CreateImageRequest() {
ARCXML ax = new ARCXML();
REQUEST req = new REQUEST();
GET_IMAGE gi = new GET_IMAGE();

ax.Item = req;
req.Item = gi;
return ax;
}

private static XmlDocument Serialize<T>(T xmlObject) {
XmlSerializer xs = new
System.Xml.Serialization.XmlSerializer(typeof(T));
StringBuilder sb = new StringBuilder();

using (XmlWriter xw = XmlWriter.Create(sb)){
XmlDocument xml = new XmlDocument();
xs.Serialize(xw, xmlObject);
xml.LoadXml(sb.ToString());
return xml;
}
}

static void Main(string[] args) {
ARCXML arcxml = CreateImageRequest();
GET_IMAGE imageRequest = ((GET_IMAGE)((REQUEST)arcxml.Item).Item);
PROPERTIES props = new PROPERTIES();

imageRequest.Items = new object[] {props};
imageRequest.ItemsElementName = new ItemsChoiceType4[] {
ItemsChoiceType4.PROPERTIES };
props.Items = new object[]{new ENVELOPE()};

TextWriterTraceListener listener = new
TextWriterTraceListener(@"c:\ArcXmlTest.trc");
Trace.AutoFlush = true;
Trace.Listeners.Add(listener);

try {

Trace.WriteLine(Serialize<GET_IMAGE>(imageRequest) .OuterXml);

Trace.WriteLine(IMSConnection.Send(arcxml.Serializ e().OuterXml));
}
catch(System.Exception e){
Trace.WriteLine(e.ToString());
}
}
}
}

"cd~" <ra*****@community.nospam> wrote in message
news:uE*************@TK2MSFTNGP10.phx.gbl...
I can provide a test app, the news server won't allow me to post the files because they are too large (93KB and 1.2KB)

I downloaded the ESRI ArcXml schema and generated the classes from the
schema using xsd.exe, which took a while because xsd doesn't handle
recursive elements very well (StackOverFlow exception during generation). Now that I have the classes I am trying to serialize them to an xml
document
to send to ArcIMS to generate map images. The .trc file is a text file
that
contains the exception information that this throws.

This is the only document I am able to find on this bug on the web,
convieniently on MSDN:
http://msdn.microsoft.com/netframewo...nges/designtim
e/xmlserial.aspx The only solution that I can come up with is to install VS2003 and
compile
the ArcXml classes since this seems to be something that has been broken in
VS2005

Thank you for your time,
Russell





Jan 30 '06 #4
Hi,

Could you send the repro project directly to me by email since I don't have
ArcXml on my machine? Remove 'online' from the nospam alias is my real
email.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Jan 31 '06 #5
cd~
I sent the projects and documentation to you yesterday, did you recieve it?

thank you!!

-R

"Kevin Yu [MSFT]" <v-****@online.microsoft.com> wrote in message
news:l4**************@TK2MSFTNGXA02.phx.gbl...
Hi,

Could you send the repro project directly to me by email since I don't
have
ArcXml on my machine? Remove 'online' from the nospam alias is my real
email.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Feb 1 '06 #6
Hi Russell,

Thank you for sending me the code. Yes, I have received it yesterday. And
it took me almost half day to debug on it. But I'm sorry, since the xsd and
the generated class was too big, I still cannot find how the problem was
caused. Looking at this issue, it might need intensive troubleshooting and
I suggest you try to contact Microsoft PSS on it. You can find their
contact information from the following link:

http://support.microsoft.com/default...;OfferProPhone

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Feb 2 '06 #7
cd~
The problem is that xsd uses an object array to store the items themselves
and an array of values from an enumeration (ItemsElementName, i believe) to
determine what type of element is stored in each array indice.
It appears that the serializer expects an object array to hold the element
type indicators and it is stored internally as an array of <enum type>,
which it can't seem to cast to an object array, thus causing the mismatch.

I appreciate the time you have spent on this.

Thank you,
-R

"Kevin Yu [MSFT]" <v-****@online.microsoft.com> wrote in message
news:zp**************@TK2MSFTNGXA02.phx.gbl...
Hi Russell,

Thank you for sending me the code. Yes, I have received it yesterday. And
it took me almost half day to debug on it. But I'm sorry, since the xsd
and
the generated class was too big, I still cannot find how the problem was
caused. Looking at this issue, it might need intensive troubleshooting and
I suggest you try to contact Microsoft PSS on it. You can find their
contact information from the following link:

http://support.microsoft.com/default...;OfferProPhone

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Feb 2 '06 #8
Sorry that I wasn't helpful. And it's glad to know that you have found the
cause of problem.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Feb 3 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
6789
by: Chris Aitchison | last post by:
Hello, I am attempting to have a class that I have written serialize so that it can be both passed as a parameter or return value for a webservice, and also be serialized to disk using the...
16
9486
by: Bob Rock | last post by:
Hello, when serializing an array of elements of a class Classname using XmlSerializer.Serialize() I get an XML like the following: <?xml version="1.0"> <ArrayOfClassname> ....... ..........
2
6789
by: Kent Boogaart | last post by:
Hello all, I have two simple classes: Item and ItemCollection. Item stores a label for the item and an instance of ItemCollection for all child items. ItemCollection just stores a collection of...
0
3006
by: keith bannister via .NET 247 | last post by:
(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...
12
8447
by: SJD | last post by:
I've just read Christoph Schittko's article on XmlSerializer: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnxmlnet/html/trblshtxsd.asp . . . and very informative it is too....
0
1167
by: Jeff T. | last post by:
I cannot figure out how to get my class to serialize the way I want it to. Basically, I have generated a number of classes using the XSD utility. I then created a derived class from one of the...
4
2680
by: BuddyWork | last post by:
Hello, When running the following line of code XmlSerializer serializer = new XmlSerializer(typeof (MyXmlTestClass)); I get the following exception message. An unhandled exception of
2
4989
by: Jinsong Liu | last post by:
I have following 3 classes public class MyMainClass { MyCollection<MyObject> m_oMyObjectCollection = null; private string m_sID = string.Empty; public MyCollection<MyObject> Collection {
2
5069
by: christopher.watford | last post by:
I'm loading a plugin assembly using Activator.CreateInstanceFrom, and inside this assembly is a settings class which gets serialized to XML. The general code flow is as follows: ObjectHandle...
0
7105
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7132
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7180
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7341
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5439
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4564
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3071
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
600
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
266
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.