I was facing the same problem in the serialization and deserialization of a custom class.
ReceiptCollection items = (ReceiptCollection)binaryFormatter.Deserialize(memoryStream) // the error happened here MemoryStream memoryStream = new MemoryStream(bytes) WHERE LogHeaderID=2' īyte bytes = (byte)cmd.ExecuteScalar() īinaryFormatter binaryFormatter = new BinaryFormatter() Using ( cmd = new (sql, connection))īyte bytes = new byte MemoryStream memoryStream = new MemoryStream() īinaryFormatter.Serialize(memoryStream, items) () VALUES binaryFormatter = new BinaryFormatter() String connectionString = 'my connection' My code sample: private void InsertObject() I am trying to insert a collection of custom class into sql database & retrieve it the insertion going well but retrieving the data & deserialize give me this error I faced this error while deserialization a custom object