E
etienne.maitre
Hi,
I work against .NET 2.0 using C# 2.0. I am facing a problem trying to
serialize the class foo (given below). Basically, foo can contain
other foos in a list. When I try to create a serializer, using the
test() method below, I get a superb StackOverflowException. I googled
for it but didn't found any answer to why I got this exception and how
to serialize foo.
Any help accepted
Thanks,
public void test()
{
XmlSerializer serializer = new XmlSerializer(typeof(foo));
....
}
[Serializable]
public class foo : IEnumerable<foo>
{
// ... some members...
List<foo> g;
public foo()
{
g = new List<foo>();
}
public IEnumerator<foo> GetEnumerator()
{
foreach (foo element in g)
{
yield return element;
}
}
System.Collections.IEnumerator
System.Collections.IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
public void Add(Object e)
{
g.Add(e as foo);
}
}
I work against .NET 2.0 using C# 2.0. I am facing a problem trying to
serialize the class foo (given below). Basically, foo can contain
other foos in a list. When I try to create a serializer, using the
test() method below, I get a superb StackOverflowException. I googled
for it but didn't found any answer to why I got this exception and how
to serialize foo.
Any help accepted
Thanks,
public void test()
{
XmlSerializer serializer = new XmlSerializer(typeof(foo));
....
}
[Serializable]
public class foo : IEnumerable<foo>
{
// ... some members...
List<foo> g;
public foo()
{
g = new List<foo>();
}
public IEnumerator<foo> GetEnumerator()
{
foreach (foo element in g)
{
yield return element;
}
}
System.Collections.IEnumerator
System.Collections.IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
public void Add(Object e)
{
g.Add(e as foo);
}
}