all groups > dotnet xml > january 2006 >
You're in the

dotnet xml

group:

XmlSerializer fails to serialize xsd.exe generated classes


XmlSerializer fails to serialize xsd.exe generated classes cd~
1/27/2006 9:06:09 AM
dotnet xml:
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/netframework/programming/breakingchanges/designtime/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




Re: XmlSerializer fails to serialize xsd.exe generated classes cd~
1/27/2006 9:25:22 AM
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.Serialize().OuterXml));
}
catch(System.Exception e){
Trace.WriteLine(e.ToString());
}
}
}
}

[quoted text, click to view]

Re: XmlSerializer fails to serialize xsd.exe generated classes cd~
1/27/2006 9:30:44 AM
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.XmlSerializationWriterGET_IMAGE.Write151_GET_IMAGE(String
n, String ns, GET_IMAGE o, Boolean isNullable, Boolean needType)
at
Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterGET_IMAGE.Write152_GET_IMAGE(Object
o)
--- End of inner exception stack trace ---
at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter,
Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String
id)
at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter 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:line 48
at ArcXmlTest.Program.Main(String[] args) in C:\Documents and
Settings\ralibey\My Documents\Visual Studio
2005\Projects\ArcXmlTest\ArcXmlTest\Program.cs:line 68

[quoted text, click to view]

Re: XmlSerializer fails to serialize xsd.exe generated classes v-terryf NO[at]SPAM online.microsoft.com (
1/30/2006 12:00:00 AM
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.)


--------------------
[quoted text, click to view]
http://msdn.microsoft.com/netframework/programming/breakingchanges/designtim
e/xmlserial.aspx
[quoted text, click to view]
Re: XmlSerializer fails to serialize xsd.exe generated classes v-kevy NO[at]SPAM online.microsoft.com
1/31/2006 12:00:00 AM
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."
Re: XmlSerializer fails to serialize xsd.exe generated classes cd~
2/1/2006 11:09:13 AM
I sent the projects and documentation to you yesterday, did you recieve it?

thank you!!

-R

[quoted text, click to view]

Re: XmlSerializer fails to serialize xsd.exe generated classes v-kevy NO[at]SPAM online.microsoft.com
2/2/2006 12:00:00 AM
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.aspx?scid=fh;EN-US;OfferProPhone

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
Re: XmlSerializer fails to serialize xsd.exe generated classes cd~
2/2/2006 4:30:14 PM
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

[quoted text, click to view]

Re: XmlSerializer fails to serialize xsd.exe generated classes v-kevy NO[at]SPAM online.microsoft.com
2/3/2006 12:00:00 AM
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."
AddThis Social Bookmark Button