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

XmlSerializer fails to serialize xsd.exe generated classes

P: n/a
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
Share this Question
Share on Google+
8 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.