Deserialization error using Runtime Serialization with the Binary Formatter

Posted by Lily on Stack Overflow See other posts from Stack Overflow or by Lily
Published on 2010-05-22T13:28:31Z Indexed on 2010/05/22 18:30 UTC
Read the original article Hit count: 917

When I am deserializing a hierarchy I get the following error

The input stream is not a valid binary format. The starting contents (in bytes) are The input stream is not a valid binary format. The starting contents (in bytes) are: 20-01-20-20-20-FF-FF-FF-FF-01-20-20-20-20-20-20-20 ..."

Any help please?

Extra info:

public void Serialize(ISyntacticNode person)
{
    Stream stream = File.Open(fileName, FileMode.OpenOrCreate);

    try
    {

        BinaryFormatter binary = new BinaryFormatter();
        pList.Add(person);
        binary.Serialize(stream, pList);
        stream.Close();
    }
    catch
    {

        stream.Close();
    }



}

public List<ISyntacticNode> Deserialize()
{
    Stream stream = File.Open(fileName, FileMode.OpenOrCreate);
    BinaryFormatter binary = new BinaryFormatter();
    try
    {
        pList = (List<ISyntacticNode>)binary.Deserialize(stream);
        binary.Serialize(stream, pList);
        stream.Close();
    }
    catch
    {
        pList = new List<ISyntacticNode>();
        binary.Serialize(stream, pList);
        stream.Close();
    }

    return pList;
}

I am Serializing a hierarchy which is of type Proxem.Antelope.Parsing.ISyntacticNode

Now I have gotten this error

System.Runtime.Serialization.SerializationException: Binary stream '116' does not contain a valid BinaryHeader. Possible causes are invalid stream or object version change between serialization and deserialization.

i'm using a different instance. How may I avoid this error please

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET