0

I am making a dotnet app that needs to read a binary file from a 3rd party. The file is containing a 516 byte header record/struct (a couple of long identifiers and a couple of fixed length char array strings) followed by a number of payload structs (240 bytes of integers and booleans and chars each).

I know I can read this file in dotnet using BinaryReader and deserialize the fields in the structs one by one.

I have poco/structs that correctly defines the properties needed for the 2 record types but I can't se anyway of letting BinaryFormatter know which type (and how much) to read from the stream next as the binder seems to be relying on typename being serialized along with record payload which they are not in this file.

I would like to know: Is there a way of doing this via the BinaryFormatter, deserializing poco's directly?

  • 4
    No, BinaryFormatter wont work for this. It would be easier to to use something like `fread` (or whatever is deemed safe currently ;p ) if the structure is a fixed. – leppie Jun 25 '19 at 21:14
  • `fread` is the `BinaryReader`. Write your own custom DeSerializer and be done with it. – H H Jun 25 '19 at 21:41
  • Possible duplicate: https://stackoverflow.com/questions/6335153/casting-a-byte-array-to-a-managed-structure – Dave M Jun 25 '19 at 23:28

0 Answers0