473,394 Members | 1,709 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

XmlSerializer exception with ArrayList

I'm not sure what I'm doing wrong here. I'm getting the exception

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

Additional information: There was an error generating the XML document."

This exception only showed up after I added the ArrayList and populated it
with an instance of RepetitionEvent.

I'm trying to serialize to Xml the class below using this function:

//--------------[ frmQuizzer.cs ]----------------------------
private void SerializeQuiz()
{
XmlSerializer serializer = new XmlSerializer(typeof(CodeSampleQuiz));
TextWriter writer = new StreamWriter("test.xml");
serializer.Serialize(writer, t);
writer.Close();
}
//-----------[ CodeSampleQuiz.cs ]-----------------------

namespace SampleQuizzer
{
public class RepetitionEvent
{
public DateTime date;
public TimeSpan duration;
}

public class CodeSampleQuiz
{
private DateTime startTime;
public ArrayList repetitionEvents = new ArrayList();
string question, answer;

public CodeSampleQuiz()
{
}

// stuff...

public void LogAnswer()
{
RepetitionEvent e = new RepetitionEvent();
e.date = DateTime.Now;
e.duration = DateTime.Now - startTime;
repetitionEvents.Add(e);
}
}
}
Nov 15 '05 #1
0 1066

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

Similar topics

3
by: zatopek | last post by:
I have a class that i wqant to serialize. This class contains an arraylist. When i fill this with strings, it files just as i want. But when i populate it with my custom class, i crashes. What...
5
by: Stuart Robertson | last post by:
I am trying to find a solution that will allow me to use XmlSerializer to serialize/deserialize a collection of objects where a given object is shared between two or more other objects, and not...
0
by: Magne Ryholt | last post by:
Have a class with a public property named "TheFirstPropertyOfArrayListType" of type ArrayList, property has attribute XmlElement to describe the contents of the ArrayList, the contents is a public...
4
by: Andy Neilson | last post by:
I've run across a strange behaviour with XmlSerializer that I'm unable to explain. I came across this while trying to use XmlSerializer to deserialize from a the details of a SoapException. This...
16
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
by: magister | last post by:
Hello I got this working but it is not how I really want it, basically I have an xml file which has a root of <test> and can be filled with 3 different types of <question> elements with different...
2
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...
3
by: Loui Mercieca | last post by:
Hi, I have created a class, named FormField , which basically contains two fields, name and value. I have set the tag before the class and the field is set as an XmlAttribute whil the name as...
1
by: Jamus Sprinson | last post by:
Before I continue, I'm going to begin by saying I'm not by any means an expert- I've been using .NET with C# for about 4 months now, and basically just learning by example and docs. A game...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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...

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.