在反序列化过程中将Filestream转换为二进制时获取异常

时间:2015-11-17 08:48:04

标签: vb.net windows

二进制流' 48'不包含有效的BinaryHeader。可能的原因是序列化和反序列化之间的无效流或对象版本更改

Dim fs As FileStream = Nothing
Try
  fs = IO.File.OpenRead(Filename)
  Dim bf As New Runtime.Serialization.Formatters.Binary.BinaryFormatter()
  bf.AssemblyFormat = Runtime.Serialization.Formatters.FormatterAssemblyStyle.Full
  bf.TypeFormat = Runtime.Serialization.Formatters.FormatterTypeStyle.TypesWhenNeeded
  fs.Position = 0
  Dim obj As Object = bf.Deserialize(fs)
  Return obj
Catch ex As Exception
  MsgBox("There was an exception while trying to convert binary file to object. Exception: " & ex.Message & " | Stacktrace: " & ex.StackTrace)
Finally
  If fs IsNot Nothing Then
    fs.Close()
  End If
End Try

任何人都可以帮助我。

0 个答案:

没有答案