【发布时间】:2018-08-16 07:00:17
【问题描述】:
我正在尝试通过网络序列化一个类,但我不断收到以下错误。
System.Runtime.Serialization.SerializationException: 'End of Stream encountered before parsing was completed.'
我看到几个线程建议将网络流转换为内存流以允许您将位置设置为 0,但这对我不起作用。
我的代码是
'Receiver
Private Sub ReceivingMethod()
Dim f As BinaryFormatter = New BinaryFormatter()
Dim msg As clsMessage
msg = f.Deserialize(TCPClient.GetStream())
ProcessMessage(msg)
Threading.Thread.Sleep(50)
End Sub
.
'Sender
Private Sub SendingMethod()
do while MessageQueue.count > 0
'Get the first message from the queue
Dim msg As clsMessage = MessageQueue(0)
Dim f As BinaryFormatter = New BinaryFormatter()
f.Serialize(TCPClient.GetStream(), msg)
MessageQueue.Remove(msg)
End If
Threading.Thread.Sleep(50)
Loop
End Sub
任何帮助将不胜感激。
【问题讨论】:
标签: vb.net serialization tcpclient tcplistener