I`am using the following code to serialize a list of bytes :
FileStream fs = new FileStream("DataFile.dat", FileMode.Create);
BinaryFormatter formatter = new BinaryFormatter();
try
{
formatter.Serialize(fs, myList);
}
catch (Exception exc)
{
Console.WriteLine("Failed to serialize. Reason: " + exc.Message);
throw;
}
finally
{
fs.Close();
}
SendFileToServer(username, "DataFile.dat", "DataFile.dat", null);
MessageBox.Show("Trimiterea detali reusita");
}
then for deserialization I`am using the following code:
List<byte[]> myList = null;
FileStream fs = new FileStream("D:\\Server\\Rares\\DataFile.dat", FileMode.Open);
try
{
BinaryFormatter formatter = new BinaryFormatter();
myList = (List<byte[]>)formatter.Deserialize(fs);
}
catch (Exception exc)
{
Console.WriteLine("Failed to deserialize. Reason: " + exc.Message);
throw;
}
finally
{
fs.Close();
}
Now my problem is that I am catching this exception:
Binary stream '0' does not contain a valid BinaryHeader. Possible causes are invalid stream or object version change between serialization and deserialization.
and I don`t know why. If you have any idea where is my problem I will apreciate your help.
Thank you in advance for your help and If you need some more information aboat my code ask me .