title: Byte array to excel workbook
body: <p>I am trying to convert a  byte array to an excel workbook. When I do this with </p>
  
  <pre><code>Response.BinaryWrite(renderedBytes);
  </code></pre>
  
  <p>it works fine and the file is as expected. But when I try to do it with this which I found online:</p>
  
  <pre><code>private Object ByteArrayToObject(byte[] arrBytes)
  {
      MemoryStream memStream = new MemoryStream();
      BinaryFormatter binForm = new BinaryFormatter();
      memStream.Write(arrBytes, 0, arrBytes.Length);
      memStream.Seek(0, SeekOrigin.Begin);
      Object obj = (Object)binForm.Deserialize(memStream);
      return obj;
  }
  </code></pre>
  
  <p>I get an error:</p>
  
  <pre><code>System.Runtime.Serialization.SerializationException: Binary stream '0' does not contain a valid BinaryHeader. Possible causes are invalid stream or object version change between serialization and deserialization.
  </code></pre>
  
  <p>Is there a difference in how binary write and deserialize work? How can I fix it?</p>
  
  <p>Thanks</p>