all groups > vb.net > september 2004 >
vb.net :
Serialization Question
Is this what you want? Dim binF As New BinaryFormatter Dim writer As New IO.StreamWriter(System.Net.Sockets.TcpClient.GetStream) binF.Serialize(writer, myArray) Lance
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.GetStream) writer.Write(myArray) Dim binF As New BinaryFormatter how can i Serialize it ? Thanks! T:-)
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 ? [quoted text, click to view] "ljlevend" <ljlevend@discussions.microsoft.com> wrote in message news:4297D41C-C0B1-466B-AD01-0ED2655F4C7E@microsoft.com... > Is this what you want? > > Dim binF As New BinaryFormatter > Dim writer As New IO.StreamWriter(System.Net.Sockets.TcpClient.GetStream) > binF.Serialize(writer, myArray) > > Lance >
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.BinaryFormatter 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.BinaryFormatter Dim mem As New IO.MemoryStream(Convert.FromBase64String(arraystring)) Return DirectCast(bf.Deserialize(mem), ArrayList) End Function /// [quoted text, click to view] > > 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.GetStream) > > writer.Write(myArray) > > Dim binF As New BinaryFormatter > > how can i Serialize it ? > > Thanks! > > T:-) > >
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.GetStream) [quoted text, click to view] "Cor Ligthert" <notfirstname@planet.nl> wrote in message news:OD2uyfklEHA.1376@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.BinaryFormatter > 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.BinaryFormatter > Dim mem As New > IO.MemoryStream(Convert.FromBase64String(arraystring)) > 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.GetStream) > > > > writer.Write(myArray) > > > > Dim binF As New BinaryFormatter > > > > how can i Serialize it ? > > > > Thanks! > > > > T:-) > > > > > >
[quoted text, click to view] > 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
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! [quoted text, click to view] "Cor Ligthert" <notfirstname@planet.nl> wrote in message news:Ow9Ky2plEHA.3524@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 > >
Tiraman this is the serialization part in my code Dim bf As New Runtime.Serialization.Formatters.Binary.BinaryFormatter 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 [quoted text, click to view] > Private client As TcpClient
Sub xxx(ByVal myArray As as Arraylist) ' passing it as arraylist saves casting [quoted text, click to view] > 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) [quoted text, click to view] > sw.Flush() > sw.Close() >
Than I think it can be something like this, not tried, I hope this helps? Cor
Hi Tiraman, Without any code, what do you think I am? Cor [quoted text, click to view] > > Now the Serialize ok but i m getting the following error in the Deserialize > method. > > System.Runtime.Serialization.SerializationException: No map for object > 1953724755. > at > System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObject() > 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:line 769" > > line 769 ---> MyArray = DirectCast(bf.Deserialize(ns), ArrayList) > > any idea ? > > Thanks ! > > "Cor Ligthert" <notfirstname@planet.nl> wrote in message > news:O7A2GhylEHA.2588@TK2MSFTNGP12.phx.gbl... > > Tiraman this is the serialization part in my code > > > > Dim bf As New Runtime.Serialization.Formatters.Binary.BinaryFormatter > > 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 > > > > > >
Hi Cor, Now the Serialize ok but i m getting the following error in the Deserialize method. System.Runtime.Serialization.SerializationException: No map for object 1953724755. at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObject() 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:line 769" line 769 ---> MyArray = DirectCast(bf.Deserialize(ns), ArrayList) any idea ? Thanks ! [quoted text, click to view] "Cor Ligthert" <notfirstname@planet.nl> wrote in message news:O7A2GhylEHA.2588@TK2MSFTNGP12.phx.gbl... > Tiraman this is the serialization part in my code > > Dim bf As New Runtime.Serialization.Formatters.Binary.BinaryFormatter > 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 > >
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(arraystring)) dim arraylist as arraylist = DirectCast(bf.Deserialize(mem), ArrayList) /// I hope this goes as well Cor
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) [quoted text, click to view] "Cor Ligthert" <notfirstname@planet.nl> wrote in message news:uOUsbw0lEHA.3156@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.SerializationException: No map for object > > 1953724755. > > at > > System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObject() > > 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:line 769" > > > > line 769 ---> MyArray = DirectCast(bf.Deserialize(ns), ArrayList) > > > > any idea ? > > > > Thanks ! > > > > "Cor Ligthert" <notfirstname@planet.nl> wrote in message > > news:O7A2GhylEHA.2588@TK2MSFTNGP12.phx.gbl... > > > Tiraman this is the serialization part in my code > > > > > > Dim bf As New Runtime.Serialization.Formatters.Binary.BinaryFormatter > > > 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 > > > > > > > > > > > >
Sorry Tiraman, Not direct, my sugestion is to put this question again as a new thread in the group. Cor [quoted text, click to view] > 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 ?
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 [quoted text, click to view] "Cor Ligthert" <notfirstname@planet.nl> wrote in message news:eI%23u2L1lEHA.3896@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(arraystring)) > dim arraylist as arraylist = DirectCast(bf.Deserialize(mem), ArrayList) > /// > > I hope this goes as well > > Cor > >
Ok, Thanks for your help. bye [quoted text, click to view] "Cor Ligthert" <notfirstname@planet.nl> wrote in message news:%232iIKW%23lEHA.1520@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 ? > >
Don't see what you're looking for? Try a search.
|
|
|