By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,225 Members | 2,170 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,225 IT Pros & Developers. It's quick & easy.

BIG Problem - Please HELP

P: n/a
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.SerializationExceptio n: BinaryFormatter Version
incompatibility. Expected Version 1.0. Received Version
1093611311.1094795601.
at
System.Runtime.Serialization.Formatters.Binary.Ser ializationHeaderRecord.Rea
d(__BinaryParser input)
at
System.Runtime.Serialization.Formatters.Binary.__B inaryParser.ReadSerializat
ionHeaderRecord()
at System.Runtime.Serialization.Formatters.Binary.__B inaryParser.Run()
at
System.Runtime.Serialization.Formatters.Binary.Obj ectReader.Deserialize(Head
erHandler handler, __BinaryParser serParser, Boolean fCheck,
IMethodCallMessage methodCallMessage)
at
System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter.Deserialize(S
tream serializationStream, HeaderHandler handler, Boolean fCheck,
IMethodCallMessage methodCallMessage)
at
System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter.Deserialize(S
tream serializationStream, HeaderHandler handler)
at
System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter.Deserialize(S
tream serializationStream)
at frmMain.DoRead(IAsyncResult ar) in frmMain.vb

Please Help

T:-)


Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Sat, 11 Sep 2004 14:23:07 +0200, Tiraman :-) wrote:
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.SerializationExceptio n: BinaryFormatter Version
incompatibility. Expected Version 1.0. Received Version
1093611311.1094795601.
at
System.Runtime.Serialization.Formatters.Binary.Ser ializationHeaderRecord.Rea
d(__BinaryParser input)
at
System.Runtime.Serialization.Formatters.Binary.__B inaryParser.ReadSerializat
ionHeaderRecord()
at System.Runtime.Serialization.Formatters.Binary.__B inaryParser.Run()
at
System.Runtime.Serialization.Formatters.Binary.Obj ectReader.Deserialize(Head
erHandler handler, __BinaryParser serParser, Boolean fCheck,
IMethodCallMessage methodCallMessage)
at
System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter.Deserialize(S
tream serializationStream, HeaderHandler handler, Boolean fCheck,
IMethodCallMessage methodCallMessage)
at
System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter.Deserialize(S
tream serializationStream, HeaderHandler handler)
at
System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter.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/de...ientSocket.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
--
Tom Shelton [MVP]
Nov 21 '05 #2

P: n/a
Hi Tom,

Now it looks good.

Thanks !

"Tom Shelton" <to*@YOUKNOWTHEDRILLmtogden.com> wrote in message
news:3b*****************************@40tude.net...
On Sat, 11 Sep 2004 14:23:07 +0200, Tiraman :-) wrote:
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.SerializationExceptio n: BinaryFormatter Version incompatibility. Expected Version 1.0. Received Version
1093611311.1094795601.
at
System.Runtime.Serialization.Formatters.Binary.Ser ializationHeaderRecord.Rea d(__BinaryParser input)
at
System.Runtime.Serialization.Formatters.Binary.__B inaryParser.ReadSerializat ionHeaderRecord()
at System.Runtime.Serialization.Formatters.Binary.__B inaryParser.Run() at
System.Runtime.Serialization.Formatters.Binary.Obj ectReader.Deserialize(Head erHandler handler, __BinaryParser serParser, Boolean fCheck,
IMethodCallMessage methodCallMessage)
at
System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter.Deserialize(S tream serializationStream, HeaderHandler handler, Boolean fCheck,
IMethodCallMessage methodCallMessage)
at
System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter.Deserialize(S tream serializationStream, HeaderHandler handler)
at
System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter.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/de...ientSocket.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
--
Tom Shelton [MVP]

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.