title: SerializationException was unhandled: The input stream is not a valid binary format. The starting contents (in bytes) are
body: <p>really stuck, any help and/or comments would be greatly appreciated!</p>
  
  <p>I've written a database program that needs to be able to load contents from a file into a list. So basically i'm trying to use serialization and deserialization for this. The area where the error occurs is in bold and is italicized: </p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.IO;
  using System.Runtime.Serialization;
  using System.Runtime.Serialization.Formatters.Binary;
  
  namespace ConsoleApplication1
  {
      class TheFile
      {
          //Version 1 serialiser, instance specific, so a bit of a pain
  
          public void SerializeObject(string filename, TheDocument document)
          {
              Stream stream = File.Open(filename, FileMode.Create);
              BinaryFormatter bFormatter = new BinaryFormatter();
              bFormatter.Serialize(stream, document);
              stream.Close();
          }
          public TheDocument DeSerializeObject(string filename)
          {
              TheDocument document;
              Stream stream = File.Open(filename, FileMode.Open);
              BinaryFormatter bFormatter = new BinaryFormatter();
              ***document = (TheDocument)bFormatter.Deserialize(stream);***
              stream.Close();
              return document;
          }
      }
  }
  </code></pre>
  
  <p>The error which i receive is as follows: The input stream is not a valid binary format. The starting contents (in bytes) are: 31-37-2F-30-39-2F-32-30-31-31-20-31-31-3A-30-36-3A ...</p>