There was an error generating the XML document.

G

Guest

Hello when I serialize an object an error generated using this function
public string SerializeObject(object oClassObject,System.Type oClassType)
{
XmlSerializer oSerializer = new XmlSerializer(oClassType);
System.Text.StringBuilder strBuilder = new System.Text.StringBuilder();
System.IO.TextWriter writer = new System.IO.StringWriter(strBuilder);
try
{
oSerializer.Serialize(writer,oClassObject);
}
catch(InvalidOperationException ex)
{
string msg = ex.Message;
string stack = ex.StackTrace;
}
return strBuilder.ToString();
}

and exception occured with message "There was an error generating the XML
document."
how can I know where is the error occured the stack trace did not give usef
info

StackTrace : " at
System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object
o, XmlSerializerNamespaces namespaces, String encodingStyle)\r\n at
System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object
o, XmlSerializerNamespaces namespaces)\r\n at
System.Xml.Serialization.XmlSerializer.Serialize(TextWriter textWriter,
Object o, XmlSerializerNamespaces namespaces)\r\n at
System.Xml.Serialization.XmlSerializer.Serialize(TextWriter textWriter,
Object o)\r\n at Test.Form1.SerializeObject(Object oClassObject, Type
oClassType) in d:\\scorm\\test\\form1.cs:line 133" string

line 133 where I called oSerializer.Serialize(writer,oClassObject);

Any Suggestions?
 
T

Teemu Keiski

And that's all the stack trace? There isn't anything more in the error
description (no description of inner exception whatsoever)?

I think you'd get replies faster by asking this at
microsoft.public.dotnet.xml group (I sent this to that group).
 
W

Wessel Troost

Can you post the definition of the class you're trying to serialize?

If the class is not serializable, the XmlSerializer is going to have a
hard time turning it into an XML document :)

Greetings,
Wessel

-----Original Message-----
From: Raed Sawalha [mailto:[email protected]]
Posted At: Sunday, April 10, 2005 11:25 AM
Posted To: microsoft.public.dotnet.framework.aspnet
Conversation: There was an error generating the XML document.
Subject: There was an error generating the XML document.

Hello when I serialize an object an error generated using this function
public string SerializeObject(object oClassObject,System.Type
oClassType)
{
XmlSerializer oSerializer = new XmlSerializer(oClassType);
System.Text.StringBuilder strBuilder = new System.Text.StringBuilder();
System.IO.TextWriter writer = new System.IO.StringWriter(strBuilder);
try
{
oSerializer.Serialize(writer,oClassObject);
}
catch(InvalidOperationException ex)
{
string msg = ex.Message;
string stack = ex.StackTrace;
}
return strBuilder.ToString();
}

and exception occured with message "There was an error generating the
XML
document."
how can I know where is the error occured the stack trace did not give
usef
info

StackTrace : " at
System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter,
Object
o, XmlSerializerNamespaces namespaces, String encodingStyle)\r\n at
System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter,
Object
o, XmlSerializerNamespaces namespaces)\r\n at
System.Xml.Serialization.XmlSerializer.Serialize(TextWriter textWriter,
Object o, XmlSerializerNamespaces namespaces)\r\n at
System.Xml.Serialization.XmlSerializer.Serialize(TextWriter textWriter,
Object o)\r\n at Test.Form1.SerializeObject(Object oClassObject, Type
oClassType) in d:\\scorm\\test\\form1.cs:line 133" string

line 133 where I called oSerializer.Serialize(writer,oClassObject);

Any Suggestions?
 
M

Matt Berther

Hello Raed,

Your code looks ok. You'll need to dig down into the InnerException ... buried
down in there you'll find the root cause of the problem.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top