Okay, The post was getting way too long and contained way too much self corrects, so I'm rewriting it from start. If you want to read back, check the changelog.
The latest revision of the code can be found here: http://pastebin.com/KMHVb5gA I'm getting an overflow in system.XML.dll for some reason; It has no stacktrace, and it just stops execution.
I have no idea WHY it overflows, but I Do know it happens after I call Save()
public bool save(string filename) //causes stack overflow when savenode is IEnumerable (and otherwise it does nothing).
{
XmlSerializer serializer = new XmlSerializer(typeof(List<savenode>));
System.IO.FileStream fstream = new System.IO.FileStream(filename, System.IO.FileMode.OpenOrCreate);
serializer.Serialize(fstream, innerdict);
fstream.Flush();
fstream.Close();
return true;
}
I'm completely new to making my own IEnumerable classes, so if you see something obvious wrong, please let me know!
The calling code looks like this:
Console.WriteLine("Commencing XML persistency test");
CedLib.Persistence.XMLPersistenceDictionary.XMLPersistenceDictionary persistence = new CedLib.Persistence.XMLPersistenceDictionary.XMLPersistenceDictionary(logger); //Works!!
persistence.Add("test", "testvaluefennecs");
Console.WriteLine(persistence["test"].obj);
foreach (var snode in persistence)
{
Console.Write("Contents: " + snode.obj);
}
persistence.save("test.xml");
persistence.load("test.xml");
if (persistence["test"].obj != "testvaluefennecs")
{
logger.logerror(new Exception("XML test failed!! Expected 'testvaluefennecs', got: " + persistence["test"].obj));
}
else
Console.WriteLine("XML test success!");
And the output like this:
Commencing XML persistency test
[17:54:09] info: Initialized new XMLPersistence dictionary
New node: test
[17:54:09] Notice: Adding new dictionary item: test
testvaluefennecs
Contents: testvaluefennecs
Process is terminated due to StackOverflowException.
Anyone have an idea? Any suggestion is welcome! I'm completely stuck on this!
[edit] Just found the exact line it overflows at, it's this:
XmlSerializer serializer = new XmlSerializer(typeof(List<savenode>));
DataContractSerializer? Maybe there is an issue with your class, not the serializer. Do other serializers fail?