1

オブジェクトを逆シリアル化しようとしていますが、このコードの最初の行で[ステップイン]をクリックすると、[続行]をクリックしたかのようにフォームに戻ります。IfElseステートメントは実行されません。

c = CType(x.Deserialize(mobjClient.GetStream), Cereal)
If c.text.Length > 0 Then
    RaiseEvent LineReceived(Me, c.text)
Else
    RaiseEvent CardReceived(Me, c)
End If

これがそれを排除するコードです

Dim x As New XmlSerializer(GetType(Cereal))
Dim c As New Cereal

クライアント側からシリアル化コードをステップスルーすることはうまくいくようです。これが私のシリアルクラスです。mobjClient.getStreamはTcpClientストリームです。

<Serializable> Public Class Cereal
    Public id As Integer
    Public cardType As Type
    Public attacker As String
    Public defender As String
    Public placedOn As String
    Public attack As Boolean
    Public placed As Boolean
    Public played As Boolean
    Public text As String

    Public Sub New()

    End Sub
End Class
4

2 に答える 2

1

これが私が修正した方法です.....最終的に、データを正しくシリアル化および逆シリアル化する方法を見つけました。

    Dim c as New Cereal
    c.text = "Testing...."
    Dim bf As New BinaryFormatter
    Dim ms As New MemoryStream
    Dim b() As Byte

    'serializes the Cereal to the created memory stream
    bf.Serialize(ms, c)
    'converts and moves into the byte array
    b = ms.ToArray()
    ms.Close()

    'send the byte array
    SyncLock mobjClient.GetStream
        mobjClient.GetStream.Write(b, 0, b.Length)
    End SyncLock

そしてここにデシリアライズがあります...

    Dim intCount As Integer

    Try
        SyncLock mobjClient.GetStream
            'returns the number of bytes to know how many to read
            intCount = mobjClient.GetStream.EndRead(ar)
        End SyncLock
        'if no bytes then we are disconnected
        If intCount < 1 Then
            MarkAsDisconnected()
            Exit Sub
        End If

        Dim bf As New BinaryFormatter
        Dim c As New Cereal
        'when data first comes on the stream it is sent to arData, then this puts into memory stream
        Dim ms As New MemoryStream(arData)

        'cut off the memory stream at the end of the data
        ms.SetLength(intCount)
        'deserialize to the created Cereal, giving us a replica of what was sent
        c = bf.Deserialize(ms)
        ms.Close()

        'starts the listener again
        mobjClient.GetStream.BeginRead(arData, 0, 3145728, AddressOf DoRead, Nothing)

        If c.text IsNot Nothing Then
            DisplayText(c.text)
        ElseIf c.OppUserID IsNot Nothing Then
            OnConnected(c.OppUserID, c.OppGender)
        ElseIf c.command IsNot Nothing Then
            OnCommandReceived(c)
        ElseIf c.hasDeck = True Or c.hasBsDeck = True Or c.hasHand = True Then
            OnDeckReceived(c)
        ElseIf c.discard = True Then
            OnDiscard(c)
        Else
            OnCardReceived(c)
        End If

    Catch e As Exception
        MarkAsDisconnected()
    End Try
于 2013-01-09T19:37:03.417 に答える
0

シリアライザは でマークされていDebuggerStepTroughます。カスタム コードで中断する場合は、カスタム コードにブレークポイントを手動で配置します。

于 2012-11-28T10:18:14.690 に答える