Click here to Skip to main content
15,911,039 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Im trying to read UINT32 numbers from binary file:

C#
try
{
   binaryStreem = new FileStream(filename, FileMode.Open, FileAccess.ReadWrite, FileShare.None);
   binaryStreem.Seek(0, 0);
   FPGATimer = (UInt32)binformater.Deserialize(binaryStreem);
   TraceParameter = (UInt32)binformater.Deserialize(binaryStreem);
   TraceLocation = (UInt32)binformater.Deserialize(binaryStreem);
   binaryStreem.Close();
}
catch (System.Exception ex)
{
   MessageBox.Show(ex.Message);
}


I get an exception when this line executes:
FPGATimer = (UInt32)binformater.Deserialize(binaryStreem);


The exception is:
{"The input stream is not a valid binary format. The starting contents (in bytes) are: 14-00-00-00-00-00-00-00-00-00-00-00-14-00-00-00-00 ..."}


What might be the probem?

Thanks.
Posted
Comments
[no name] 9-Dec-12 6:07am    
If I'm not mistaken, you're re-writing it..
columbos14927 9-Dec-12 6:11am    
The binary file generated by other application and im trying to read it.

1 solution

Your file was not written with a BinaryFormatter - so you can't read it back with one.
A quick look at the data shown in your error message would indicate that it is raw binary data, possibly the 32 bit integers 20, 0, 0, 20
A binary formatter output file looks more like this:
0001000000FFFFFFFF01000000000000
0004010000000C53797374656D2E496E
74333201000000076D5F76616C756500
08140000000B0001000000FFFFFFFF01
0000000000000004010000000C537973
74656D2E496E74333201000000076D5F
76616C75650008140000000B
That, by the way, is for the two integer values "20" and "20" - but the binary formatter adds the class names and related info to it.

You either need to look at the data writer, or modify your code to read raw data - if you know what the content is supposed to be, that would help.
 
Share this answer
 
Comments
columbos14927 9-Dec-12 6:15am    
So if i have a given binary file: memory_dump.bin
How should i modify my code to read raw data?

Thanks
OriginalGriff 9-Dec-12 6:52am    
Depends - do you know the length of each element? It's difficult to tell from just looking at the data in the error message, because the only non-zero elements are only aligned on a four byte boundary, so it could be 32 bit integer values 20, 0, 0, 20, 0, ... or it could be very different. Do you have any info on what any of the values should be? Have you examined it with a hex editor?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900