greetngs,
i have two classes:
[Serializable]
public class FireGridUnit
{
public GridUnit FireGridLocation { get; set; }
}
[Serializable]
public class FireResult: FireGridUnit
{
public bool Hit { get; set; }
public bool ShipDestroyed { get; set; }
public Ship.ValidShips DestroyedShipType {get; set;}
public bool Win { get; set; }
}
as you see FireResult inherits FireGrdUnit.
in my code when i try to use them i get a runtime error:
Unable to cast object of type 'NietzscheBattleships.FireGridUnit' to type 'NietzscheBattleships.FireResult'.
is this because if i am serializing the class has to be independant ie not be inherited?
many thanks.
EDIT:
it happens here:
XmlSerializer ss;
StringWriter ww;
ss = new XmlSerializer(typeof(FireResult));
ww = new StringWriter();
ss.Serialize(ww, fireGridUnit);
MessageBox.Show("hello");
MessageBox.Show(ww.ToString());
it gives the error mentioned. if i take this out then it runs but obviously not doing what want it to do.
EDIT: i got it my mistake!
ss.Serialize(ww, fireGridUnit); should be ss.Serialize(ww, fireResult);
thanks.