2015-11-06 62 views
2

反序列化我得到错误:分析完成前遇到的流结束。而在vb.net

End of Stream encountered before parsing was completed while deserializing the file

代码:

Dim fs As FileStream = Nothing 

    Try 
    fs = IO.File.OpenRead(Filename) 
    'fs = New FileStream(Filename, FileMode.Open) 


     Dim bf As New Runtime.Serialization.Formatters.Binary.BinaryFormatter() 

     bf.AssemblyFormat = Runtime.Serialization.Formatters.FormatterAssemblyStyle.Full 
     bf.TypeFormat = Runtime.Serialization.Formatters.FormatterTypeStyle.TypesWhenNeeded 
     fs.Seek(0, SeekOrigin.Begin) 
     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 

我与fs.Position=0也尝试过,甚至它不工作。

任何人都可以帮助我。在此先感谢

回答

1

该错误可能是序列化代码的一部分。 请现在摆脱这两个过程中的格式属性,并确保您在任何可能的地方都使用using,以便所有流,作者,读者及其包装的所有字节都已被刷新。

+0

谢谢,你可以请我发布这两个程序的标准代码。我应该使用哪些格式属性? – user2845419

+0

我从来没有使用过它们。 – doker

+0

请发布您的代码序列化,所以我们可以看到。我不再流利地使用vv.net,但是如果你显示你的代码,我们可能会发现一些快速的东西。 – doker