i created a class that i want to serialize each time a move is made on the chessboard.
class ClassMoveToSerialize
{
int[] StartPosition;
int[] EndPosition;
Dictionary<int[], int[]> serialized;
public void DataToSerialize(int rowStartSerialize, int columnStartSerialize, int rowEndSerialize, int columnEndSerialize)
{
MessageBox.Show("" + (number = int rowEndSerialize+columnEndSerialize));
//it isnt finished, i am only testing them right now.
}
}
i created two methods outside the class that will enable me to serialize and deserialize. (the methods are activated in the partial form class).
public static bool WasntSerialized;
public void SerializeNow()
{
ClassMoveToSerialize serializeMeh = new ClassMoveToSerialize();
FileStream f = new FileStream(@"K:\MiniSteam\ChessGame\Replays\Replays.dat", FileMode.Create);
BinaryFormatter b = new BinaryFormatter();
b.Serialize(f, serializeMeh);// i get the exception here
f.Close();
}
public void DeSierializeNow()
{
ClassMoveToSerialize serializeMeh = new ClassMoveToSerialize();
FileStream f = new FileStream(@"K:\MiniSteam\ChessGame\Replays\Replays.dat", FileMode.Open);
BinaryFormatter b = new BinaryFormatter();
serializeMeh = (ClassMoveToSerialize)b.Deserialize(f);
f.Close();
}
i have another code in another class file that activates those methods.
if (WasntSerialized)
{
chess.DeSierializeNow();// when another move is made, this method should deserialize all the moves
WasntSerialized = false;
}
toSerialize.DataToSerialize(rowStart, columnStart, rowEnd, columnEnd);
if (!WasntSerialized)
{
chess.SerializeNow();// The move coordinates should be saved after this method invoked.
WasntSerialized = true;
}
why do i get the exception in the SerializeNow() method?