I am new to this site so I apologize for any improper formatting on my part.
I'm working on a project and am trying to Serialize a class that contains a List of type TDF_Test
into an XML file but I keep getting the error "There was an error reflecting type LoadInformation
".
I've read the Inner Exception as well and it says "There was an error reflecting property 'testList'". testList is the list of objects I'm trying to serialize.
Here is my class containing the List I want to serialize and save to an XML file.
namespace SPCTool.Core_Classes
{
public class LoadInformation
{
public LoadInformation()
{
testList = new List<TDF.TDF_Test>();
}
public List<TDF.TDF_Test> testList
{ get; set; }
}
}
Here is how I save it to the XML
LoadInformation info = new LoadInformation();
info.testList = someList; // someList is the same type as testList
SaveXML.SaveData(info, filename);
Here is the stacktrace:
at SPCTool.User_Interfaces.MainForm.saveToolStripMenuItem_Click(Object sender, EventArgs e) in
M:\astburyj_TestProcess\IGXLTestProcess\TestProcess\tools\SPCReviewTool\SPCReviewTool\User Interface\MainForm.cs:line 940
Here is the class SaveXML
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.IO;
namespace SPCTool.Core_Classes
{
public class SaveXML
{
public static void SaveData(object obj, string filename)
{
XmlSerializer sr = new XmlSerializer(obj.GetType());
TextWriter writer = new StreamWriter(filename);
sr.Serialize(writer, obj);
writer.Close();
}
}
}
I've done a lot of searching and haven't found a good solution. Does anyone know what I can do? Let me know if you need any other information or code.
Thanks a lot.