二进制格式化程序错误 [英] Binary formatter error

查看:243
本文介绍了二进制格式化程序错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从二进制文件中读取UINT32数字:



 尝试 
{
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);
}





此行执行时出现异常:

 FPGATimer =(UInt32)binformater.Deserialize(binaryStreem); 





例外是:

 {输入流不是有效的二进制格式。起始内容(以字节为单位)为:14-00-00-00-00-00-00-00-00-00-00-00-14 -00-00-00-00 ...} 





什么可能是探测器?



谢谢。

解决方案

你的文件不是用二进制格式编写的 - 所以你不能用它来读回来。 />
快速查看错误消息中显示的数据将表明它是原始二进制数据,可能是32位整数20,0,0,20

二进制格式化程序输出文件看起来更像是这样:

 0001000000FFFFFFFF01000000000000 
0004010000000C53797374656D2E496E
74333201000000076D5F76616C756500
08140000000B0001000000FFFFFFFF01
00000000000 00004010000000C537973
74656D2E496E74333201000000076D5F
76616C75650008140000000B

顺便提一下,这是两个整数值20和20 - 但二进制格式化程序将类名和相关信息添加到它。



您要么需要查看数据编写器,要么修改代码以读取原始数据 - 如果您知道内容应该是什么,那就是帮助


Im trying to read UINT32 numbers from binary file:

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.

解决方案

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.


这篇关于二进制格式化程序错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆