473,324 Members | 2,179 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Convert a serialized object into string

I have a class containing string variables, hashtables..I managed to
serialize it into a memory stream instead of file stream. Would like to know
how can I convert the byte array to string. I tried using
encoding.default.getstring but the output is an empty string..(:..damn!

partial code example that copied for microsoft for testing purpose:
Dim addresses As New Hashtable
addresses.Add("Jeff", "123 Main Street, Redmond, WA 98052")
addresses.Add("Fred", "987 Pine Road, Phila., PA 19116")
addresses.Add("Mary", "PO Box 112233, Palo Alto, CA 94301")
Dim mstrm As New MemoryStream
Dim formatter As New BinaryFormatter
formatter.Serialize(mstrm, addresses)
dim str as string = encoding.default.getstring(mstrm.toarray)

Please advise.
Nov 22 '05 #1
6 2486
Red Devil,

The nices one I know

\\\ from a message from Tom Shelton
Private Function SerializeFontObject(ByVal fnt As Font) As String
Dim bf As New BinaryFormatter
Dim mem As New MemoryStream
Try
bf.Serialize(mem, fnt)
Return Convert.ToBase64String(mem.ToArray())
Catch
Return String.Empty
Finally
mem.Close()
End Try
End Function
Private Function DeserializeFontObject(ByVal fnt As String) As Font
Dim bf As New BinaryFormatter
Dim mem As New MemoryStream(Convert.FromBase64String(fnt))
Try
Return DirectCast(bf.Deserialize(mem), Font)
Finally
If Not mem Is Nothing Then
mem.Close()
End If
End Try
End Function
///

I hope this helps a little bit?

Cor
Nov 22 '05 #2
Cor,

Awesome...juz what I'm looking for...

thanx a lot..appreciate that.
"Cor Ligthert" wrote:
Red Devil,

The nices one I know

\\\ from a message from Tom Shelton
Private Function SerializeFontObject(ByVal fnt As Font) As String
Dim bf As New BinaryFormatter
Dim mem As New MemoryStream
Try
bf.Serialize(mem, fnt)
Return Convert.ToBase64String(mem.ToArray())
Catch
Return String.Empty
Finally
mem.Close()
End Try
End Function
Private Function DeserializeFontObject(ByVal fnt As String) As Font
Dim bf As New BinaryFormatter
Dim mem As New MemoryStream(Convert.FromBase64String(fnt))
Try
Return DirectCast(bf.Deserialize(mem), Font)
Finally
If Not mem Is Nothing Then
mem.Close()
End If
End Try
End Function
///

I hope this helps a little bit?

Cor

Nov 22 '05 #3
Cor,

Another problem occurred. It doesn't happen all time thou. I did a load test
using load runner. On an occassion, the serialized string is incomplete.

Encounter such problem before?

The data is sent from client to server via socket.

"Cor Ligthert" wrote:
Red Devil,

The nices one I know

\\\ from a message from Tom Shelton
Private Function SerializeFontObject(ByVal fnt As Font) As String
Dim bf As New BinaryFormatter
Dim mem As New MemoryStream
Try
bf.Serialize(mem, fnt)
Return Convert.ToBase64String(mem.ToArray())
Catch
Return String.Empty
Finally
mem.Close()
End Try
End Function
Private Function DeserializeFontObject(ByVal fnt As String) As Font
Dim bf As New BinaryFormatter
Dim mem As New MemoryStream(Convert.FromBase64String(fnt))
Try
Return DirectCast(bf.Deserialize(mem), Font)
Finally
If Not mem Is Nothing Then
mem.Close()
End If
End Try
End Function
///

I hope this helps a little bit?

Cor

Nov 22 '05 #4
Red Devil,

That is the part I don't like.

However set a message in the newsgroup

microsoft.public.dotnet.languages.vb

There this probem is often handled. Although you can have the same results
here.

So crossposting to both newsgroups with your problem.(one message to both in
one time) will probably give you the best results.

Cor
Nov 22 '05 #5
Cor,

What do you mean by 'That is the part I don't like.'?

"Cor Ligthert" wrote:
Red Devil,

That is the part I don't like.

However set a message in the newsgroup

microsoft.public.dotnet.languages.vb

There this probem is often handled. Although you can have the same results
here.

So crossposting to both newsgroups with your problem.(one message to both in
one time) will probably give you the best results.

Cor

Nov 22 '05 #6
Red Devil,
The data is sent from client to server via socket.


I don't like it being busy in that area, I never did, that is all.

Cor
Nov 22 '05 #7

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

Similar topics

6
by: Red Devil | last post by:
I have a class containing string variables, hashtables..I managed to serialize it into a memory stream instead of file stream. Would like to know how can I convert the byte array to string. I tried...
2
by: andrew lowe | last post by:
Hi, Please bear with me on this problem, first I'll give you some background: I have an object that contains a DateTime field which i pass to a webservice public class Foo { public DateTime...
6
by: Gator | last post by:
Hi All, Basically my situation is this, I have a server implemented in C++, unmanaged code, using proprietery protocol over TCP/IP to communicate with the cilent(c++ also). Now, I am implementing...
7
by: John Grandy | last post by:
make a call to XML Web Service WebMethod ... returns object myArray with no error ... myArray contains objects of type StringKeyStringValue runtime error occurs on accessing properties of...
0
by: Pierre | last post by:
Hi, I'm trying to select specific nodes from a XmlDocument filled with a serialized object and to insert these nodes into another XmlDocument. The object is well serialized (see below). From a...
5
by: EqDev | last post by:
I have a class that is a control derived from UserControl. I want to use serialization and deserialization with this calss but I get an exception "Cannot serialize member...
0
by: madani | last post by:
Hi, I need to get serialized string of Page ViewState in Constructor of my custom web control. I can not override SavePageStateToPersistenceMedium Method of page object because I'm in different...
3
by: MMiGG | last post by:
Hi Our project need parse JAVA serialized object string in C, has any library? Thanx
15
by: Buddy Home | last post by:
Hello, I'm trying to speed up a piece of code that is causing performance issues with our product. The problem is we are using serialization to convert the object to a string, this is costing us...
5
by: sklett | last post by:
I wasn't sure how to phrase the subject. Currently I'm storing a file as a byte in a database, when I want to work with the file I download the byte and write the data to a file on disk then...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.