I am writing a small navigation app for Windows Mobile 6.1 (.NET CF 3.5), and I am getting IOException when I try to deserialize my data from file stream, and I cant understand why. here is some of my code:
//That's the class I am trying to serialize / deserialize
public class MapData
{
[XmlIgnore]
public Bitmap EntireMapBitmap { get; set; }
public string Date { get; set; }
public string FileName { get; set; }
public Route NavigationRoute { get; set; }
//and some other unrelavant fields...
}
here is the code to serialize:
string fileNameWithExtension = /*some calculation to get the full path*/
XmlSerializer serializer = new XmlSerializer(typeof(MapData));
TextWriter textWriter = new StreamWriter(fileNameWithExtension);
serializer.Serialize(textWriter, mapData);
textWriter.Close();
here is the code for deserialization:
string fullPath = /*Retreive file's full path logic - working OK */;
XmlSerializer deserializer = new XmlSerializer(typeof(MapData));
FileStream fs = new FileStream(fullPath, FileMode.Open);
mapData = null;
mapData = (MapData)deserializer.Deserialize(fs);
fs.Close();
I know thats a lot of details, but from my interrogation, the Exception only occurs when I am making a use with the NavigationRoute poroperty, so I will add those related classes also...
public class Route
{
public List<GeographicCoordinate> Coordinates { get; set; }
public Route()
{
Coordinates = new List<GeographicCoordinate>();
}
}
public class GeographicCoordinate
{
public int LocationOnMap_X { get; private set; }
public int LocationOnMap_Y { get; private set; }
public GeographicCoordinate(Point onMap)
{
LocationOnMap_X = onMap.X;
LocationOnMap_Y = onMap.Y;
}
}
As I mentioned before, its only after I add one or more objects to the Coordinates list of the Route - I get the exception (which makes it even more awkward to me...). Another thing I tried to do it to remove the private setters from GeographicCoordinate class - but it was no good. Thanks everyone :)