472,354 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,354 software developers and data experts.

Serialization Question

Hi,

i have a StreamWriter that hold a System.Net.Sockets.NetwrokStream
and the StreamWriter Object Hold An ArrayList which
i would like to Serialize And Send it back to the client via the
StreamWriter.Flush()
Dim writer As New IO.StreamWriter(System.Net.Sockets.TcpClient.GetSt ream)

writer.Write(myArray)

Dim binF As New BinaryFormatter

how can i Serialize it ?

Thanks!

T:-)
Nov 21 '05 #1
14 2287
Is this what you want?

Dim binF As New BinaryFormatter
Dim writer As New IO.StreamWriter(System.Net.Sockets.TcpClient.GetSt ream)
binF.Serialize(writer, myArray)

Lance

Nov 21 '05 #2
yes,

but this what i tried and it didn't work for me since the
BinaryFormatter.Serialize doesn't accept a StreamWriter :)

do you know other way to implement this kind of operation ?

"ljlevend" <lj******@discussions.microsoft.com> wrote in message
news:42**********************************@microsof t.com...
Is this what you want?

Dim binF As New BinaryFormatter
Dim writer As New IO.StreamWriter(System.Net.Sockets.TcpClient.GetSt ream)
binF.Serialize(writer, myArray)

Lance

Nov 21 '05 #3
Hi Tiraman,

This sample I once made should do the job for you.

I hope this helps?

Cor

\\\
Private Sub Form1_Load(ByVal sender _
As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim a As New ArrayList
a.Add("I ")
a.Add("hope ")
a.Add("this ")
a.Add("helps?")
Dim b As String = SerializeArraylist(a)
MessageBox.Show(b)
Dim c As ArrayList = DeserializeArraylist(b)
End Sub
Private Function SerializeArraylist(ByVal _
arraylst As ArrayList) As String
Dim bf As New
Runtime.Serialization.Formatters.Binary.BinaryForm atter
Dim mem As New IO.MemoryStream
bf.Serialize(mem, arraylst)
Return Convert.ToBase64String(mem.ToArray())
End Function
Private Function DeserializeArraylist(ByVal _
arraystring As String) As ArrayList
Dim bf As New
Runtime.Serialization.Formatters.Binary.BinaryForm atter
Dim mem As New
IO.MemoryStream(Convert.FromBase64String(arraystri ng))
Return DirectCast(bf.Deserialize(mem), ArrayList)
End Function
///

i have a StreamWriter that hold a System.Net.Sockets.NetwrokStream
and the StreamWriter Object Hold An ArrayList which
i would like to Serialize And Send it back to the client via the
StreamWriter.Flush()
Dim writer As New IO.StreamWriter(System.Net.Sockets.TcpClient.GetSt ream)

writer.Write(myArray)

Dim binF As New BinaryFormatter

how can i Serialize it ?

Thanks!

T:-)

Nov 21 '05 #4
Hi Cor ,

it is a good example but it is not cover my problem.

I have a NetworkStream Which I m getting into the StreamWriter which i would
like to serialize.

how can i do that ?

Thanks!

Dim writer As New IO.StreamWriter(System.Net.Sockets.TcpClient.GetSt ream)

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:OD**************@TK2MSFTNGP12.phx.gbl...
Hi Tiraman,

This sample I once made should do the job for you.

I hope this helps?

Cor

\\\
Private Sub Form1_Load(ByVal sender _
As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim a As New ArrayList
a.Add("I ")
a.Add("hope ")
a.Add("this ")
a.Add("helps?")
Dim b As String = SerializeArraylist(a)
MessageBox.Show(b)
Dim c As ArrayList = DeserializeArraylist(b)
End Sub
Private Function SerializeArraylist(ByVal _
arraylst As ArrayList) As String
Dim bf As New
Runtime.Serialization.Formatters.Binary.BinaryForm atter
Dim mem As New IO.MemoryStream
bf.Serialize(mem, arraylst)
Return Convert.ToBase64String(mem.ToArray())
End Function
Private Function DeserializeArraylist(ByVal _
arraystring As String) As ArrayList
Dim bf As New
Runtime.Serialization.Formatters.Binary.BinaryForm atter
Dim mem As New
IO.MemoryStream(Convert.FromBase64String(arraystri ng))
Return DirectCast(bf.Deserialize(mem), ArrayList)
End Function
///

i have a StreamWriter that hold a System.Net.Sockets.NetwrokStream
and the StreamWriter Object Hold An ArrayList which
i would like to Serialize And Send it back to the client via the
StreamWriter.Flush()
Dim writer As New IO.StreamWriter(System.Net.Sockets.TcpClient.GetSt ream)
writer.Write(myArray)

Dim binF As New BinaryFormatter

how can i Serialize it ?

Thanks!

T:-)


Nov 21 '05 #5
> Hi Cor ,

it is a good example but it is not cover my problem.

I have a NetworkStream Which I m getting into the StreamWriter which i would like to serialize.

how can i do that ?

Thanks!


Yes and what is wrong with it the sample first serialize and than deserilize
in one sample.

You have to use serialize, stream, and deserialize, however that was not the
problem I thought?

Cor
Nov 21 '05 #6
Hello Cor,

I m not sure that i understood you so here is my example and i will be happy
if you let me know where , what and why is the problem :-)
Private client As TcpClient

Sub xxx(ByVal obj As Object)

SyncLock client.GetStream
Dim sw As New IO.StreamWriter(client.GetStream)

sw.Write(CType(obj,ArrayList))

Dim bf As New BinaryFormatter

bf.Serialize(sw, obj)
sw.Flush()
sw.Close()

End SyncLock

End Sub

Thanks!

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:Ow**************@TK2MSFTNGP12.phx.gbl...
Hi Cor ,

it is a good example but it is not cover my problem.

I have a NetworkStream Which I m getting into the StreamWriter which i would
like to serialize.

how can i do that ?

Thanks!


Yes and what is wrong with it the sample first serialize and than

deserilize in one sample.

You have to use serialize, stream, and deserialize, however that was not the problem I thought?

Cor

Nov 21 '05 #7
Tiraman this is the serialization part in my code

Dim bf As New Runtime.Serialization.Formatters.Binary.BinaryForm atter
dim mem As New IO.MemoryStream
bf.Serialize(mem, arraylst)
Dim myString as STring = Convert.ToBase64String(mem.ToArray())

When I look at your code I see
Private client As TcpClient Sub xxx(ByVal myArray As as Arraylist) ' passing it as arraylist saves
casting Dim sw As New IO.StreamWriter(client.GetStream)
Dim bf As New BinaryFormatter dim mem As New IO.MemoryStream
bf.Serialize(mem, myArray)
Dim myString as String =
Convert.ToBase64String(mem.ToArray())
sw.Write(myString) sw.Flush()
sw.Close()

Than I think it can be something like this, not tried,

I hope this helps?

Cor
Nov 21 '05 #8
Hi Cor,

Now the Serialize ok but i m getting the following error in the Deserialize
method.

System.Runtime.Serialization.SerializationExceptio n: No map for object
1953724755.
at
System.Runtime.Serialization.Formatters.Binary.__B inaryParser.ReadObject()
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:line 769"

line 769 ---> MyArray = DirectCast(bf.Deserialize(ns), ArrayList)

any idea ?

Thanks !

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:O7**************@TK2MSFTNGP12.phx.gbl...
Tiraman this is the serialization part in my code

Dim bf As New Runtime.Serialization.Formatters.Binary.BinaryForm atter
dim mem As New IO.MemoryStream
bf.Serialize(mem, arraylst)
Dim myString as STring = Convert.ToBase64String(mem.ToArray())

When I look at your code I see
Private client As TcpClient Sub xxx(ByVal myArray As as Arraylist) ' passing it as arraylist

saves casting
Dim sw As New IO.StreamWriter(client.GetStream)
Dim bf As New BinaryFormatter

dim mem As New IO.MemoryStream
bf.Serialize(mem, myArray)
Dim myString as String =
Convert.ToBase64String(mem.ToArray())
sw.Write(myString)
sw.Flush()
sw.Close()

Than I think it can be something like this, not tried,

I hope this helps?

Cor

Nov 21 '05 #9
Hi Tiraman,

Without any code, what do you think I am?

Cor

Now the Serialize ok but i m getting the following error in the Deserialize method.

System.Runtime.Serialization.SerializationExceptio n: No map for object
1953724755.
at
System.Runtime.Serialization.Formatters.Binary.__B inaryParser.ReadObject()
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:line 769"

line 769 ---> MyArray = DirectCast(bf.Deserialize(ns), ArrayList)

any idea ?

Thanks !

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:O7**************@TK2MSFTNGP12.phx.gbl...
Tiraman this is the serialization part in my code

Dim bf As New Runtime.Serialization.Formatters.Binary.BinaryForm atter
dim mem As New IO.MemoryStream
bf.Serialize(mem, arraylst)
Dim myString as STring = Convert.ToBase64String(mem.ToArray())

When I look at your code I see
Private client As TcpClient

Sub xxx(ByVal myArray As as Arraylist) ' passing it as arraylist

saves
casting
Dim sw As New IO.StreamWriter(client.GetStream)
Dim bf As New BinaryFormatter

dim mem As New IO.MemoryStream
bf.Serialize(mem, myArray)
Dim myString as String =
Convert.ToBase64String(mem.ToArray())
sw.Write(myString)
sw.Flush()
sw.Close()

Than I think it can be something like this, not tried,

I hope this helps?

Cor


Nov 21 '05 #10
A Good Guy :-)

here is the code,

Dim ns As NetworkStream = client.GetStream()

Dim bf As New BinaryFormatter

Dim myarray As New ArrayList

myarray = DirectCast(bf.Deserialize(ns), ArrayList)
"Cor Ligthert" <no**********@planet.nl> wrote in message
news:uO**************@TK2MSFTNGP12.phx.gbl...
Hi Tiraman,

Without any code, what do you think I am?

Cor

Now the Serialize ok but i m getting the following error in the

Deserialize
method.

System.Runtime.Serialization.SerializationExceptio n: No map for object
1953724755.
at
System.Runtime.Serialization.Formatters.Binary.__B inaryParser.ReadObject() 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:line 769"

line 769 ---> MyArray = DirectCast(bf.Deserialize(ns), ArrayList)

any idea ?

Thanks !

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:O7**************@TK2MSFTNGP12.phx.gbl...
Tiraman this is the serialization part in my code

Dim bf As New Runtime.Serialization.Formatters.Binary.BinaryForm atter
dim mem As New IO.MemoryStream
bf.Serialize(mem, arraylst)
Dim myString as STring = Convert.ToBase64String(mem.ToArray())

When I look at your code I see

> Private client As TcpClient
Sub xxx(ByVal myArray As as Arraylist) ' passing it as arraylist

saves
casting
> Dim sw As New IO.StreamWriter(client.GetStream)
> Dim bf As New BinaryFormatter
dim mem As New IO.MemoryStream
bf.Serialize(mem, myArray)
Dim myString as String =
Convert.ToBase64String(mem.ToArray())
sw.Write(myString)
> sw.Flush()
> sw.Close()
>
Than I think it can be something like this, not tried,

I hope this helps?

Cor



Nov 21 '05 #11
Tiraman,

Roughly written in this message.

\\\
dim ns as new IO.streamreader
Dim ns As NetworkStream = client.GetStream()
dim arraystring as string = ns.read
Dim bf As New BinaryFormatter
Dim mem As New IO.MemoryStream(Convert.FromBase64String(arraystri ng))
dim arraylist as arraylist = DirectCast(bf.Deserialize(mem), ArrayList)
///

I hope this goes as well

Cor
Nov 21 '05 #12
Hi Cor,
Once Again Thanks for your help.

now every thing working fine but i still have one problem.
with the Convert.FromBase64String i can work with very small strings and i
would like to
work with more then 64 bit.

any idea ?

Thanks

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:eI****************@TK2MSFTNGP15.phx.gbl...
Tiraman,

Roughly written in this message.

\\\
dim ns as new IO.streamreader
Dim ns As NetworkStream = client.GetStream()
dim arraystring as string = ns.read
Dim bf As New BinaryFormatter
Dim mem As New IO.MemoryStream(Convert.FromBase64String(arraystri ng))
dim arraylist as arraylist = DirectCast(bf.Deserialize(mem), ArrayList)
///

I hope this goes as well

Cor

Nov 21 '05 #13
Sorry Tiraman,

Not direct, my sugestion is to put this question again as a new thread in
the group.

Cor

Once Again Thanks for your help.

now every thing working fine but i still have one problem.
with the Convert.FromBase64String i can work with very small strings and i
would like to
work with more then 64 bit.

any idea ?

Nov 21 '05 #14
Ok,
Thanks for your help.
bye

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
Sorry Tiraman,

Not direct, my sugestion is to put this question again as a new thread in
the group.

Cor

Once Again Thanks for your help.

now every thing working fine but i still have one problem.
with the Convert.FromBase64String i can work with very small strings and i would like to
work with more then 64 bit.

any idea ?


Nov 21 '05 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Bob Rock | last post by:
Hello, when serializing an array of elements of a class Classname using XmlSerializer.Serialize() I get an XML like the following: <?xml version="1.0"> <ArrayOfClassname> ....... ..........
3
by: Aaron Clamage | last post by:
Hi, I'm not sure that if this is the right forum, but any help would be greatly appreciated. I am porting some java serialization code to c# and I can't figure out the correct way to do it. ...
5
by: francois | last post by:
First of all I would to to apologize for resending this post again but I feel like my last post as been spoiled Here I go for my problem: Hi, I have a webservice that I am using and I would...
6
by: Uttam | last post by:
Hello, We are at a very crucial decision making stage to select between .Net and Java. Our requirement is to download a class at runtime on the client computer and execute it using remoting or...
0
by: eSapient | last post by:
I generated serialization/deserialization code for this schema using the xsd tool: <?xml version="1.0" encoding="UTF-8"?> <xs:schema elementFormDefault="qualified"...
6
by: John Glover | last post by:
I'm having a very strange problem with XML serialization. I'm writing web services which pass instances of various classes back and forth as parameters and return values of web methods. The...
15
by: Jacques | last post by:
Hi I am an dotNet newby, so pardon my ignorance. I am looking for a method of saving/copying a managed class to a stream/file WITHOUT saving the object's state, eg. if I have a ref class with...
0
by: groovyghoul | last post by:
Hi I have the following XML file: =========================================================== <?xml version="1.0" encoding="UTF-16"?> <Policy xmlns="http://tempuri.org/richard.xsd"> <TransType...
0
by: nobin01 | last post by:
Dear sir; I want ur Help in serialization.I know serialization.I Know binary,soap and xmlserialization also.But i want ur help in following topics.pls help me as soon as possible.I have search in...
2
by: mkvenkit.vc | last post by:
Hello, I hope this is the right place to post a question on Boost. If not, please let me know where I can post this message and I will do so. I am having a strange problem with std::string as...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
1
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. header("Location:".$urlback); Is this the right layout the...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it so the python app could use a http request to get...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.