二进制格式化程序错误

编程入门 行业动态 更新时间:2024-10-23 22:27:51
本文介绍了二进制格式化程序错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试图从二进制文件中读取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.

更多推荐

二进制格式化程序错误

本文发布于:2023-11-08 15:51:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1569808.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   程序

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!