How to deserialze a binary file

I'm having some trouble figuring out how to deserialize a binary file. I mostly can't figure out how to use the second argument of SerializationInfo.GetValue(); - if I just put a type keyword there, it's invalid, and if I use the TypeCode, it's invalid as well. This is my current attempt (obviously it doesn't build).

protected GroupMgr(SerializationInfo info, StreamingContext context) { Groups = (Dictionary<int, Group>) info.GetValue("Groups", (Type) TypeCode.Object); Linker = (Dictionary<int, int>) info.GetValue("Linker", (Type) TypeCode.Object ); }


The second argument in SerializationInfo.GetValue is the object type:

protected GroupMgr(SerializationInfo info, StreamingContext context) {
Groups = (Dictionary<int, Group>) info.GetValue("Groups", typeof(Dictionary<int, Group>));
Linker = (Dictionary<int, int>) info.GetValue("Linker", typeof(Dictionary<int, int>));




where instance is an object. Of course, replace by the actual types in your case.

Instantiate temporary variables:

Dictionary<int, Group> tmpDict = new Dictionary<int, Group>();
Dictionary<int, int> tmpLinker = new Dictionary<int, int>();

then in your lines below:

Groups = (Dictionary<int, Group>) info.GetValue("Groups", tmpDict.GetType());
Linker = (Dictionary<int, int>) info.GetValue("Linker", tmpLinker.GetType());

Hope this helps, Best regards, Tom.

Category:c# Time:2009-11-24 Views:1

Related post

  • How do I tell Subversion to treat a file as a binary file? 2008-09-16

    How do I tell Subversion (svn) to treat a file as a binary file? --------------Solutions------------- It is possible to manually identify a file located within a repository as binary by using: svn propset svn:mime-type application/octet-stream <fi

  • Locking binary files using git version control system 2008-09-23

    For one and a half years, I have been keeping my eyes on the git community in hopes of making the switch away from SVN. One particular issue holding me back is the inability to lock binary files. Throughout the past year I have yet to see development

  • Is it legal to reverse engineer binary file formats 2008-09-23

    Is it legal to add support for a 3rd party file format in my application by reverse engineer a unencrypted binary file format from another application, and reading the contents? --------------Solutions------------- Depends on your location. In the EU

  • Read and write from/to a binary file in Matlab 2008-10-15

    My knowledge of matlab is merely on a need to know basis, so this is probably an elementary question. Nevertheless here it comes: I have got a file containing data (16-bit integers) stored in binary format. How do I read it into a vector /an array in

  • What exactly causes binary file "gibberish"? 2008-10-19

    I haven't found an answer to this particular question; perhaps there isn't one. But I've been wondering for a while about it. What exactly causes a binary file to display as "gibberish" when you look at it in a text editor? It's the same thing with e

  • Removing a sequence of characters from a large binary file using python 2008-10-21

    I would like to trim long sequences of the same value from a binary file in python. A simple way of doing it is simply reading in the file and using re.sub to replace the unwanted sequence. This will of course not work on large binary files. Can it b

  • Determine target architecture of binary file in Linux (library or executable) 2008-11-06

    We have an issue related to a Java application running under a (rather old) FC3 on a Advantech POS board with a Via C3 processor. The java application has several compiled shared libs that are accessed via JNI. Via C3 processor is suppossed to be i68

  • Best way to read structured binary files with Java 2008-11-10

    I have to read a binary file in a legacy format with Java. In a nutshell the file has a header consisting of several integers, bytes and fixed-length char arrays, followed by a list of records which also consist of integers and chars. In any other la

  • Resolving a Git conflict with binary files 2008-11-10

    I've been using Git on Windows (msysgit) to track changes for some design work I've been doing. Today I've been working on a different PC (with remote repo brian) and I'm now trying to merge the edits done today back into my regular local version on

  • What are important points when designing a (binary) file format? 2008-11-27

    When designing a file format for recording binary data, what attributes would you think the format should have? So far, I've come up with the following important points: have some "magic bytes" at the beginning, to be able to recognize the files (in

  • Include binary file with GNU ld linker script 2008-11-29

    I have a working linker script. I want to add another data section whose contents is pulled directly from a file (ld shouldn't parse it and extract the sections and so on). How can I do that? OUTPUT_FORMAT("elf32-i386") ENTRY(start) SECTIONS { .text

  • PowerShell based database synchronisation using a binary file 2008-12-01

    I have written a database application using a binary file as storage. it is accessed via powershell cmdlets. You can put information into the database using the put- and you can read information using get-. The problem is synchronisation. What is the

  • how to read NASA .hgt binary files 2008-12-10

    I'm sure this is really simple if you know anything about binary files, but I'm a newbie on that score. How would I extract the data from NASA .hgt files? Here is a description from The SRTM data files have names like

  • How do you run a binary file that neither Windows nor Cygwin can execute? 2008-12-25

    I haven't loaded up a VM of Linux yet (I have OpenSUSE on a VM on my machine), but whenever I run the executable under Cygwin, I get the error message "cannot execute binary file". Windows (PowerShell) tells me that it can't find the command that is

  • How to parse a binary file with floats (Java generated) using Cocoa Touch? 2008-12-30

    Given the following Java code for generating a binary file: DataOutputStream out = new DataOutputStream(new FileOutputStream("foo.dat")); out.writeInt(1234); out.writeShort(30000); out.writeFloat(256.384f); I'm using the following Objective-C code an

  • What is the simplest way to parse binary files in Cocoa Touch? 2008-12-31

    Say I have a binary file (generated with Java) containing a 32 bit int value. I'm currently using the following Objective-C code for parsing it: NSString *path = [[NSBundle mainBundle] pathForResource:@"foo" ofType:@"dat"]; NSFileHandle *file = [NSFi

  • How to get a recursive svn blame report in a single xml file for all non-binary files in a branch? 2009-01-05

    How can I get a fully recursive svn blame report for all non-binary files in a branch, where the output is in a single file in xml format and includes revision, date, author, filename & path, and the text of the line of the file itself? The entir

  • Tools to help reverse engineer binary file formats 2009-01-29

    What tools are available to aid in decoding unknown binary data formats? I know Hex Workshop and 010 Editor both support structures. These are okay to a limited extent for a known fixed format but get difficult to use with anything more complicated,

  • Joining Binary files that have been split via download 2009-02-02

    Hi I am trying to join a number of binary files that were split during download. The requirement stemmed from the project In this project author allows you to download files by providing a url. The problem comes throu

Copyright (C), All Rights Reserved.

processed in 0.506 (s). 13 q(s)