Ok I figured something out. I had been using the SoapFormatter for my serialization. I found this code on the net it works as I hoped it doesnt mind if I have changed my class and added properties when it loads the data.
/// <summary>
/// Serializes an object instance to a file.
/// </summary>
/// <param name="Instance">the object instance to serialize</param>
/// <param name="Filename"></param>
/// <param name="BinarySerialization">determines whether XML serialization or binary serialization is used</param>
/// <returns></returns>
public static bool SerializeObject(object Instance, string Filename,
bool BinarySerialization)
{
bool retVal = true;
if (!BinarySerialization)
{
XmlTextWriter writer = null;
try
{
XmlSerializer serializer =
new XmlSerializer(Instance.GetType());
// Create an XmlTextWriter using a FileStream.
Stream fs = new FileStream(Filename, FileMode.Create);
writer = new XmlTextWriter(fs, new UTF8Encoding());
writer.Formatting = Formatting.Indented;
writer.IndentChar = ;
writer.Indentation = 3;
// Serialize using the XmlTextWriter.
serializer.Serialize(writer,Instance);
}
catch(Exception e)
{
MessageBox.Show(e.Message);
retVal = false;
}
finally
{
if (writer != null)
writer.Close();
}
}
else
{
Stream fs = null;
try
{
BinaryFormatter serializer = new BinaryFormatter();
fs = new FileStream(Filename, FileMode.Create);
serializer.Serialize(fs,Instance);
}
catch
{
retVal = false;
}
finally
{
if (fs != null)
fs.Close();
}
}
return retVal;
}
/// <summary>
/// Deserializes an object from file and returns a reference.
/// </summary>
/// <param name="Filename">name of the file to serialize to</param>
/// <param name="ObjectType">The Type of the object. Use typeof(yourobject class)</param>
/// <param name="BinarySerialization">determines whether we use Xml or Binary serialization</param>
/// <returns>Instance of the deserialized object or null. Must be cast to your object type</returns>
public static object DeSerializeObject(string Filename,Type ObjectType,
bool BinarySerialization)
{
object Instance = null;
if (!BinarySerialization)
{
XmlReader reader = null;
XmlSerializer serializer = null;
FileStream fs = null;
try
{
// Create an instance of the XmlSerializer specifying type and namespace.
serializer = new XmlSerializer(ObjectType);
// A FileStream is needed to read the XML document.
fs = new FileStream(Filename, FileMode.Open);
reader = new XmlTextReader(fs);
Instance = serializer.Deserialize(reader);
}
catch
{
return null;
}
finally
{
if (fs != null)
fs.Close();
if (reader != null)
reader.Close();
}
}
else
{
BinaryFormatter serializer = null;
FileStream fs = null;
try
{
serializer = new BinaryFormatter();
fs = new FileStream(Filename, FileMode.Open);
Instance = serializer.Deserialize(fs);
}
catch
{
return null;
}
finally
{
if (fs != null)
fs.Close();
}
}
return Instance;
}