You didn't provide a complete program, nor the exception, but I cobbled
together an example using your code that works:
using System;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using System.Collections;
namespace tApp
{
public class TestClass
{
public string myStr;
public TestClass() {}
public TestClass(string s)
{
myStr = s;
}
}
public class Class1
{
public static void Main()
{
ArrayList arr = new ArrayList();
for(int i=0; i<5; i++)
{
arr.Add(new TestClass((string)"Line #" + i.ToString()));
}
XmlSerializer xser = new XmlSerializer(typeof(ArrayList), new Type[]
{typeof(TestClass)});
MemoryStream stream = new MemoryStream();
XmlWriter writer = new XmlTextWriter(stream, System.Text.Encoding.ASCII);
xser.Serialize(writer, arr);
}
}
}
--
C#, .NET and Complex Adaptive Systems:
http://blogs.geekdojo.net/Richard
"Chuck Bowling" <ch**********@sbcglobal-NO-SPAM.net> wrote in message
news:O2**************@TK2MSFTNGP12.phx.gbl...
I'm really stumped on this. Serializing an ArrayList to XML works fine
when i use built in classes but when i try storing my own classes in ArrayLists
and serializing them the CLR throwns an exception. Can someone give me a
clue as to what's going on?
using System;
using System.Collections;
namespace tApp
{
public class TestClass
{
public string myStr;
public TestClass(string s)
{
myStr = s;
}
}
public class Class1
{
public ArrayList arr;
public Class1()
{
arr = new ArrayList();
for(int i=0; i<5; i++)
{
arr.Add(new TestClass((string)"Line #" + i.ToString()));
}
}
}
}