code_junkie

Deserialization throws an exception for this bit of C# code [closed]

Nov 12th, 2011
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. // Fake way of getting some binary (image) data.
  2. byte[] data = File.ReadAllBytes("Chick.jpg");
  3.  
  4. using (Stream originalBinaryDataStream = new MemoryStream(data))
  5. {
  6. // This works perfectly fine, if use this method (which i can't).
  7. //image = new Bitmap("Chick.jpg");
  8.  
  9. // This throws an exception when it's deserialized.
  10. // It doesn't like the memory stream reference?
  11. image = new Bitmap(originalBinaryDataStream);
  12. }
  13.  
  14. private void Form1_Load(object sender, EventArgs e)
  15. {
  16. byte[] data = File.ReadAllBytes("c:\t.jpg");
  17.  
  18. using (Stream originalBinaryDataStream = new MemoryStream(data))
  19. {
  20. // This works perfectly fine, if use this method (which i can't).
  21. //image = new Bitmap("Chick.jpg");
  22.  
  23.  
  24. // This throws an exception when it's deserialized.
  25. // It doesn't like the memory stream reference?
  26. originalBinaryDataStream.Seek(0, SeekOrigin.End);
  27. pictureBox1.Image= new Bitmap(originalBinaryDataStream);
  28. }
  29. }
Add Comment
Please, Sign In to add comment