0

我正在尝试序列化一个对象,但我不断收到以下错误:

解析完成前遇到的流结束

我在读取之前将流位置设置为 0,我确保在读取和写入时使用相同的格式化程序(二进制格式化程序),并且我还确保我正在刷新流。我还可以做些什么。下面,你可以找到我的代码。

Stream stream = File.Open("MyFile.bin", FileMode.Create);
BinaryFormatter bFormatter = new BinaryFormatter();
bFormatter.Serialize(stream, searchPage);
stream.Flush();
stream.Close();
4

0 回答 0