Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. BinaryFormatter.Deserialization SerializationException

BinaryFormatter.Deserialization SerializationException

Scheduled Pinned Locked Moved C#
helpquestionalgorithms
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Trapper Hell
    wrote on last edited by
    #1

    I have been working on this issue for a few days now and I am growing tired and desperate :sigh: I have made this application which sends a screenshot (Image type) to another PC. All works well on most PCs except some very few of them. Those that do not work complain of a Binary stream '0' does not contain a valid BinaryHeader. The code is exactly the same on the working / non-working PCs. I have also attempted to run the program locally on the PCs not working, and the exact problem occurs. The Algorithm is as follows: - Screenshot is taken (returned as Image) - Size of the Image is sent (to prepare a byte[] for the receiving end) - Image is converted into a MemoryStream from BinaryFormatter.Serialize - MemoryStream.ToArray() gets byte[] which is written on a NetworkStream - Receiving end receives the length of the object and prepares a byte[] with that length - Receiving end reads the data on a byte[] - Byte[] is Deserialized to object <- Exception occurs X| I have checked the first 50 bytes being sent and received and they are exactly identical!! :doh: It is true that the first byte is a 0 but this works with no problems at all on other systems Why is this happening? How can I avoid this? Maybe using UnsafeDeserialize or something completely different?! :confused: Any help is sooo greatly appreciated!!

    L 1 Reply Last reply
    0
    • T Trapper Hell

      I have been working on this issue for a few days now and I am growing tired and desperate :sigh: I have made this application which sends a screenshot (Image type) to another PC. All works well on most PCs except some very few of them. Those that do not work complain of a Binary stream '0' does not contain a valid BinaryHeader. The code is exactly the same on the working / non-working PCs. I have also attempted to run the program locally on the PCs not working, and the exact problem occurs. The Algorithm is as follows: - Screenshot is taken (returned as Image) - Size of the Image is sent (to prepare a byte[] for the receiving end) - Image is converted into a MemoryStream from BinaryFormatter.Serialize - MemoryStream.ToArray() gets byte[] which is written on a NetworkStream - Receiving end receives the length of the object and prepares a byte[] with that length - Receiving end reads the data on a byte[] - Byte[] is Deserialized to object <- Exception occurs X| I have checked the first 50 bytes being sent and received and they are exactly identical!! :doh: It is true that the first byte is a 0 but this works with no problems at all on other systems Why is this happening? How can I avoid this? Maybe using UnsafeDeserialize or something completely different?! :confused: Any help is sooo greatly appreciated!!

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi, I don't know what problem you are having. One possibility is the (de)serializer is having an out-of-memory problem due to fragmentation in the large-object-heap. Why do you need serialization at all? Couldn't you use Bitmap.Save(NetworkStream) and new Bitmap(NetworkStream)? I don't like your scheme requiring a potentially large array that much. :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups