Problem with Xml Serialization

J

Jax

I have a rather large class that i'm looking to serialize
to Xml.
Whenever it tries to serialize it I get this error message:

An unhandled exception of
type 'System.InvalidOperationException' occurred in
system.xml.dll

Additional information: There was an error
reflecting 'VestaQuoteV1.Case'.

As it's a little vague i'm having difficulty in detecting
what it is that is causing this problem.
There are arraylists involved within the class although
each of these are prefixed with the:

[XmlElement(Type = typeof(Customer))]

element. Thereby getting rid of any problems with
serializing the weakly typed collections.

I've also tried using a SOAP formatter:

Case c = new Case();
FileStream myStream = File.Create("case.xml");
SoapFormatter myXMLFormat = new SoapFormatter();
myXMLFormat.Serialize(myStream, c);
myStream.Close();

But that just produces an xml file of a size of 0 bytes.

My original code for serialization is this:

Case c = new Case();
string path = @"c:\VestaQuote\case.xml";
TextWriter tr = new StreamWriter(path);
XmlSerializer sr = new XmlSerializer(typeof(Case));
sr.Serialize(tr,c);
tr.Close();

Can anyone give me pointers so i can tell what to look out
for while analyzing my class, or know of this problem and
know of any ways around it.
As always, I am sincerely grateful for any assistance.

Jax
 
J

Jax

I should post better examples, my class actually went:

Case c = new Case("Ref");

The constructor needing a string, i added an empty
constructor and it worked fine.
 

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

Top