BIG Problem - Please HELP

T

Tiraman :-\)

Hi Everyone,

i have the following problem in my client-server Application

My server take array and serialize it into the memorystream

Dim ns As NetworkStream = client.GetStream()
Dim writer As New IO.StreamWriter(ns)
Dim bf As New BinaryFormatter
Dim mem As New IO.MemoryStream
bf.Serialize(mem, myArray)

Then we are converting the memory stream into Base64String
Dim myString As String = Convert.ToBase64String(mem.ToArray())

And in the end the server write the string back to the client
writer.Write(myString)
writer.Flush()
so far so good :)

but now in the client side i have some problem in the Deserialize row

I Have an asynchronous reading from the NetworkStream

Const READ_BUFFER_SIZE As Integer = 255
Private readBuffer(READ_BUFFER_SIZE) As Byte

client.GetStream.BeginRead(readBuffer, 0, READ_BUFFER_SIZE,
AddressOf DoRead, Nothing)

Private Sub DoRead(ByVal ar As IAsyncResult)
Dim bf As New BinaryFormatter
Dim mem As New IO.MemoryStream(readBuffer)
Dim myarray As ArrayList = DirectCast(bf.Deserialize(mem),
ArrayList)

End Sub

This Is The Error,

System.Runtime.Serialization.SerializationException: BinaryFormatter Version
incompatibility. Expected Version 1.0. Received Version
1093611311.1094795601.
at
System.Runtime.Serialization.Formatters.Binary.SerializationHeaderRecord.Rea
d(__BinaryParser input)
at
System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadSerializat
ionHeaderRecord()
at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run()
at
System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(Head
erHandler handler, __BinaryParser serParser, Boolean fCheck,
IMethodCallMessage methodCallMessage)
at
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(S
tream serializationStream, HeaderHandler handler, Boolean fCheck,
IMethodCallMessage methodCallMessage)
at
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(S
tream serializationStream, HeaderHandler handler)
at
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(S
tream serializationStream)
at frmMain.DoRead(IAsyncResult ar) in frmMain.vb



Please Help

T:)
 
T

Tom Shelton

Hi Everyone,

i have the following problem in my client-server Application

My server take array and serialize it into the memorystream

Dim ns As NetworkStream = client.GetStream()
Dim writer As New IO.StreamWriter(ns)
Dim bf As New BinaryFormatter
Dim mem As New IO.MemoryStream
bf.Serialize(mem, myArray)

Then we are converting the memory stream into Base64String
Dim myString As String = Convert.ToBase64String(mem.ToArray())

And in the end the server write the string back to the client
writer.Write(myString)
writer.Flush()
so far so good :)

but now in the client side i have some problem in the Deserialize row

I Have an asynchronous reading from the NetworkStream

Const READ_BUFFER_SIZE As Integer = 255
Private readBuffer(READ_BUFFER_SIZE) As Byte

client.GetStream.BeginRead(readBuffer, 0, READ_BUFFER_SIZE,
AddressOf DoRead, Nothing)

Private Sub DoRead(ByVal ar As IAsyncResult)
Dim bf As New BinaryFormatter
Dim mem As New IO.MemoryStream(readBuffer)
Dim myarray As ArrayList = DirectCast(bf.Deserialize(mem),
ArrayList)

End Sub

This Is The Error,

System.Runtime.Serialization.SerializationException: BinaryFormatter Version
incompatibility. Expected Version 1.0. Received Version
1093611311.1094795601.
at
System.Runtime.Serialization.Formatters.Binary.SerializationHeaderRecord.Rea
d(__BinaryParser input)
at
System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadSerializat
ionHeaderRecord()
at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run()
at
System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(Head
erHandler handler, __BinaryParser serParser, Boolean fCheck,
IMethodCallMessage methodCallMessage)
at
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(S
tream serializationStream, HeaderHandler handler, Boolean fCheck,
IMethodCallMessage methodCallMessage)
at
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(S
tream serializationStream, HeaderHandler handler)
at
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(S
tream serializationStream)
at frmMain.DoRead(IAsyncResult ar) in frmMain.vb



Please Help

T:)

Tiraman...

There are a couple of issues here. On the client side, you have to realize
that your object is not necessarily going to come over in one piece. Data
sent over TCP is broken into packets. So, you will probably want to append
a new line or some other non-printable character to the base64 encoded so
that the client will know when the data transmission is complete. You're
using async reads, so you'll need to make sure you keep state between calls
to your read method... Check the examples here for further details:

http://msdn.microsoft.com/library/d...e/html/cpconUsingNon-blockingClientSocket.asp

Now, once you have that part worked out... You'll need to make sure that
you convert your decode your string back to a byte array BEFORE
deserializing it...

' remember to remove the appended new line first...
Dim buffer() As Byte = Convert.FromBase64String (yourObjectString)

once you've done that, you can then deserialize...

Dim ms As New MemoryStream (buffer)
Dim bf As New BinaryFormatter()
Dim al As ArrayList = DirectCast (bf.Deserialize (ms), ArrayList)

HTH
 
T

Tiraman :-\)

Hi Tom,

Now it looks good.

Thanks !

Tom Shelton said:
Tiraman...

There are a couple of issues here. On the client side, you have to realize
that your object is not necessarily going to come over in one piece. Data
sent over TCP is broken into packets. So, you will probably want to append
a new line or some other non-printable character to the base64 encoded so
that the client will know when the data transmission is complete. You're
using async reads, so you'll need to make sure you keep state between calls
to your read method... Check the examples here for further details:

http://msdn.microsoft.com/library/d...e/html/cpconUsingNon-blockingClientSocket.asp

Now, once you have that part worked out... You'll need to make sure that
you convert your decode your string back to a byte array BEFORE
deserializing it...

' remember to remove the appended new line first...
Dim buffer() As Byte = Convert.FromBase64String (yourObjectString)

once you've done that, you can then deserialize...

Dim ms As New MemoryStream (buffer)
Dim bf As New BinaryFormatter()
Dim al As ArrayList = DirectCast (bf.Deserialize (ms), ArrayList)

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top