473,544 Members | 1,939 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Serialization Question

Hi,

i have a StreamWriter that hold a System.Net.Sock ets.NetwrokStre am
and the StreamWriter Object Hold An ArrayList which
i would like to Serialize And Send it back to the client via the
StreamWriter.Fl ush()
Dim writer As New IO.StreamWriter (System.Net.Soc kets.TcpClient. GetStream)

writer.Write(my Array)

Dim binF As New BinaryFormatter

how can i Serialize it ?

Thanks!

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

Dim binF As New BinaryFormatter
Dim writer As New IO.StreamWriter (System.Net.Soc kets.TcpClient. GetStream)
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******@discu ssions.microsof t.com> wrote in message
news:42******** *************** ***********@mic rosoft.com...
Is this what you want?

Dim binF As New BinaryFormatter
Dim writer As New IO.StreamWriter (System.Net.Soc kets.TcpClient. GetStream)
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(ByVa l sender _
As Object, ByVal e As System.EventArg s) Handles MyBase.Load
Dim a As New ArrayList
a.Add("I ")
a.Add("hope ")
a.Add("this ")
a.Add("helps?")
Dim b As String = SerializeArrayl ist(a)
MessageBox.Show (b)
Dim c As ArrayList = DeserializeArra ylist(b)
End Sub
Private Function SerializeArrayl ist(ByVal _
arraylst As ArrayList) As String
Dim bf As New
Runtime.Seriali zation.Formatte rs.Binary.Binar yFormatter
Dim mem As New IO.MemoryStream
bf.Serialize(me m, arraylst)
Return Convert.ToBase6 4String(mem.ToA rray())
End Function
Private Function DeserializeArra ylist(ByVal _
arraystring As String) As ArrayList
Dim bf As New
Runtime.Seriali zation.Formatte rs.Binary.Binar yFormatter
Dim mem As New
IO.MemoryStream (Convert.FromBa se64String(arra ystring))
Return DirectCast(bf.D eserialize(mem) , ArrayList)
End Function
///

i have a StreamWriter that hold a System.Net.Sock ets.NetwrokStre am
and the StreamWriter Object Hold An ArrayList which
i would like to Serialize And Send it back to the client via the
StreamWriter.Fl ush()
Dim writer As New IO.StreamWriter (System.Net.Soc kets.TcpClient. GetStream)

writer.Write(my Array)

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.Soc kets.TcpClient. GetStream)

"Cor Ligthert" <no**********@p lanet.nl> wrote in message
news:OD******** ******@TK2MSFTN GP12.phx.gbl...
Hi Tiraman,

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

I hope this helps?

Cor

\\\
Private Sub Form1_Load(ByVa l sender _
As Object, ByVal e As System.EventArg s) Handles MyBase.Load
Dim a As New ArrayList
a.Add("I ")
a.Add("hope ")
a.Add("this ")
a.Add("helps?")
Dim b As String = SerializeArrayl ist(a)
MessageBox.Show (b)
Dim c As ArrayList = DeserializeArra ylist(b)
End Sub
Private Function SerializeArrayl ist(ByVal _
arraylst As ArrayList) As String
Dim bf As New
Runtime.Seriali zation.Formatte rs.Binary.Binar yFormatter
Dim mem As New IO.MemoryStream
bf.Serialize(me m, arraylst)
Return Convert.ToBase6 4String(mem.ToA rray())
End Function
Private Function DeserializeArra ylist(ByVal _
arraystring As String) As ArrayList
Dim bf As New
Runtime.Seriali zation.Formatte rs.Binary.Binar yFormatter
Dim mem As New
IO.MemoryStream (Convert.FromBa se64String(arra ystring))
Return DirectCast(bf.D eserialize(mem) , ArrayList)
End Function
///

i have a StreamWriter that hold a System.Net.Sock ets.NetwrokStre am
and the StreamWriter Object Hold An ArrayList which
i would like to Serialize And Send it back to the client via the
StreamWriter.Fl ush()
Dim writer As New IO.StreamWriter (System.Net.Soc kets.TcpClient. GetStream)
writer.Write(my Array)

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.GetStrea m
Dim sw As New IO.StreamWriter (client.GetStre am)

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**********@p lanet.nl> wrote in message
news:Ow******** ******@TK2MSFTN GP12.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.Seriali zation.Formatte rs.Binary.Binar yFormatter
dim mem As New IO.MemoryStream
bf.Serialize(me m, arraylst)
Dim myString as STring = Convert.ToBase6 4String(mem.ToA rray())

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.GetStre am)
Dim bf As New BinaryFormatter dim mem As New IO.MemoryStream
bf.Serialize(me m, myArray)
Dim myString as String =
Convert.ToBase6 4String(mem.ToA rray())
sw.Write(myStri ng) 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.S erializationExc eption: No map for object
1953724755.
at
System.Runtime. Serialization.F ormatters.Binar y.__BinaryParse r.ReadObject()
at System.Runtime. Serialization.F ormatters.Binar y.__BinaryParse r.Run()
at
System.Runtime. Serialization.F ormatters.Binar y.ObjectReader. Deserialize(Hea d
erHandler handler, __BinaryParser serParser, Boolean fCheck,
IMethodCallMess age methodCallMessa ge)
at
System.Runtime. Serialization.F ormatters.Binar y.BinaryFormatt er.Deserialize( S
tream serializationSt ream, HeaderHandler handler, Boolean fCheck,
IMethodCallMess age methodCallMessa ge)
at
System.Runtime. Serialization.F ormatters.Binar y.BinaryFormatt er.Deserialize( S
tream serializationSt ream, HeaderHandler handler)
at
System.Runtime. Serialization.F ormatters.Binar y.BinaryFormatt er.Deserialize( S
tream serializationSt ream)
at frmMain.DoRead( IAsyncResult ar) in frmMain.vb:line 769"

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

any idea ?

Thanks !

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

Dim bf As New Runtime.Seriali zation.Formatte rs.Binary.Binar yFormatter
dim mem As New IO.MemoryStream
bf.Serialize(me m, arraylst)
Dim myString as STring = Convert.ToBase6 4String(mem.ToA rray())

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.GetStre am)
Dim bf As New BinaryFormatter

dim mem As New IO.MemoryStream
bf.Serialize(me m, myArray)
Dim myString as String =
Convert.ToBase6 4String(mem.ToA rray())
sw.Write(myStri ng)
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.S erializationExc eption: No map for object
1953724755.
at
System.Runtime. Serialization.F ormatters.Binar y.__BinaryParse r.ReadObject()
at System.Runtime. Serialization.F ormatters.Binar y.__BinaryParse r.Run()
at
System.Runtime. Serialization.F ormatters.Binar y.ObjectReader. Deserialize(Hea d erHandler handler, __BinaryParser serParser, Boolean fCheck,
IMethodCallMess age methodCallMessa ge)
at
System.Runtime. Serialization.F ormatters.Binar y.BinaryFormatt er.Deserialize( S tream serializationSt ream, HeaderHandler handler, Boolean fCheck,
IMethodCallMess age methodCallMessa ge)
at
System.Runtime. Serialization.F ormatters.Binar y.BinaryFormatt er.Deserialize( S tream serializationSt ream, HeaderHandler handler)
at
System.Runtime. Serialization.F ormatters.Binar y.BinaryFormatt er.Deserialize( S tream serializationSt ream)
at frmMain.DoRead( IAsyncResult ar) in frmMain.vb:line 769"

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

any idea ?

Thanks !

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

Dim bf As New Runtime.Seriali zation.Formatte rs.Binary.Binar yFormatter
dim mem As New IO.MemoryStream
bf.Serialize(me m, arraylst)
Dim myString as STring = Convert.ToBase6 4String(mem.ToA rray())

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.GetStre am)
Dim bf As New BinaryFormatter

dim mem As New IO.MemoryStream
bf.Serialize(me m, myArray)
Dim myString as String =
Convert.ToBase6 4String(mem.ToA rray())
sw.Write(myStri ng)
sw.Flush()
sw.Close()

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

I hope this helps?

Cor


Nov 21 '05 #10

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

Similar topics

16
9495
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> ....... ....... </ArrayOfClassname>
3
3160
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. It seems that either I can use default serialization or implement ISerializable. Is there any way to do both (e.g. extend the default...
5
2813
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 like it to return an XML serialized version of an object.
6
2705
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 rmi. Just to keep my question short I am posting trimmed version of my code. //file: Serializable.cs
0
1704
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" attributeFormDefault="unqualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:complexType name="FAAAvxType"> <xs:sequence> <xs:choice>
6
6046
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 problem is that in my derived classes, the XML that is automatically generated is lacking the properties of the base class. For example: public class...
15
2375
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 two int32's as its data members, the binary file of that class must have a size of 8 bytes (i.e. only contains class data members, not methods etc.)....
0
1795
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 /> <LOB /> <Name> <FirstName />
0
1191
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 site but only basics serialization is there. Topics: 1) serialize a nested object in mutiple files by maintaining the relation on parent level. ...
2
5542
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 I am trying to read from a binary archive using Boost serialization. I am new to this, and it is possible that I have not understood the usage. In...
0
7420
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7602
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7764
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7368
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7704
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5904
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5291
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4911
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3407
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...

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.