C# inheritance XmlSerializer

Posted by ikurtz on Stack Overflow See other posts from Stack Overflow or by ikurtz
Published on 2010-03-22T16:31:14Z Indexed on 2010/03/22 16:41 UTC
Read the original article Hit count: 562

Filed under:
|

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.

© Stack Overflow or respective owner

Related posts about c#

Related posts about xml-serialization