473,698 Members | 2,295 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Deserializing from string

I need to serialise a business object into a session as a string. The reason
for this is that we have to run session state with classic ASP and the code
we use in effect mean ASP.net sessions can only handle strings. My initial
thought is to serialize the object into a string and put it into the session
but I am having problem deserializing it.

Code to serialise
login = New login.clsLogin
Dim objStream As New MemoryStream
Dim objFormatter As New BinaryFormatter

objFormatter.Se rialize(objStre am, login)
Session("login" ) = login

Code to deserialise

Dim objFormatter As New BinaryFormatter
Dim enc As New UTF8Encoding
Dim arrBytData() As Byte = enc.GetBytes(Se ssion("login"). ToString)
Dim ms As MemoryStream = New MemoryStream()
ms.Write(arrByt Data, 0, arrBytData.Leng th)
ms.Seek(0, 0)
login = objFormatter.De serialize(ms)

The error I get is:

End of Stream encountered before parsing was completed.

Can anyone point me in the right direction. Regards, Chris.
Jan 22 '07 #1
2 1558
Figured it out

Dim MyFormatter As New BinaryFormatter ()
Dim ms As New MemoryStream
MyFormatter.Ser ialize(ms, login)

Dim bytearray As Byte() = ms.ToArray()
Dim str As String = Convert.ToBase6 4String(bytearr ay)
Session("login" ) = str
Dim objFormatter As New BinaryFormatter
Dim GenericObject As Object
Dim arrBytData() As Byte =
Convert.FromBas e64String(Sessi on("login").ToS tring)
Dim ms As MemoryStream = New MemoryStream(ar rBytData)

ms.Write(arrByt Data, 0, arrBytData.Leng th)
ms.Seek(0, SeekOrigin.Begi n)
GenericObject = objFormatter.De serialize(ms)
login = CType(GenericOb ject, login.clsLogin)

"Chris" <no****@nospam. comwrote in message
news:uI******** *****@TK2MSFTNG P06.phx.gbl...
>I need to serialise a business object into a session as a string. The
reason for this is that we have to run session state with classic ASP and
the code we use in effect mean ASP.net sessions can only handle strings. My
initial thought is to serialize the object into a string and put it into
the session but I am having problem deserializing it.

Code to serialise
login = New login.clsLogin
Dim objStream As New MemoryStream
Dim objFormatter As New BinaryFormatter

objFormatter.Se rialize(objStre am, login)
Session("login" ) = login

Code to deserialise

Dim objFormatter As New BinaryFormatter
Dim enc As New UTF8Encoding
Dim arrBytData() As Byte = enc.GetBytes(Se ssion("login"). ToString)
Dim ms As MemoryStream = New MemoryStream()
ms.Write(arrByt Data, 0, arrBytData.Leng th)
ms.Seek(0, 0)
login = objFormatter.De serialize(ms)

The error I get is:

End of Stream encountered before parsing was completed.

Can anyone point me in the right direction. Regards, Chris.

Jan 22 '07 #2
Good, but the line:
ms.Write(arrByt Data, 0, arrBytData.Leng th)
is unncessary, you have alreader wrapped the MemoryStream around the
arrBytData byte array and the data is already there.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"Chris" wrote:
Figured it out

Dim MyFormatter As New BinaryFormatter ()
Dim ms As New MemoryStream
MyFormatter.Ser ialize(ms, login)

Dim bytearray As Byte() = ms.ToArray()
Dim str As String = Convert.ToBase6 4String(bytearr ay)
Session("login" ) = str
Dim objFormatter As New BinaryFormatter
Dim GenericObject As Object
Dim arrBytData() As Byte =
Convert.FromBas e64String(Sessi on("login").ToS tring)
Dim ms As MemoryStream = New MemoryStream(ar rBytData)

ms.Write(arrByt Data, 0, arrBytData.Leng th)
ms.Seek(0, SeekOrigin.Begi n)
GenericObject = objFormatter.De serialize(ms)
login = CType(GenericOb ject, login.clsLogin)

"Chris" <no****@nospam. comwrote in message
news:uI******** *****@TK2MSFTNG P06.phx.gbl...
I need to serialise a business object into a session as a string. The
reason for this is that we have to run session state with classic ASP and
the code we use in effect mean ASP.net sessions can only handle strings. My
initial thought is to serialize the object into a string and put it into
the session but I am having problem deserializing it.

Code to serialise
login = New login.clsLogin
Dim objStream As New MemoryStream
Dim objFormatter As New BinaryFormatter

objFormatter.Se rialize(objStre am, login)
Session("login" ) = login

Code to deserialise

Dim objFormatter As New BinaryFormatter
Dim enc As New UTF8Encoding
Dim arrBytData() As Byte = enc.GetBytes(Se ssion("login"). ToString)
Dim ms As MemoryStream = New MemoryStream()
ms.Write(arrByt Data, 0, arrBytData.Leng th)
ms.Seek(0, 0)
login = objFormatter.De serialize(ms)

The error I get is:

End of Stream encountered before parsing was completed.

Can anyone point me in the right direction. Regards, Chris.


Jan 23 '07 #3

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

Similar topics

5
4628
by: Artur Niesporek | last post by:
Hi guys, when receiving a soap response posted back from a server i get the following error when deserializing the soap message. The problem seems to be with the item-collection of the nightlyrate-Array. .] Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Re ad6_nightlyratearray()
1
1852
by: Thomas | last post by:
Hi, I implemented a composite pattern which should be serializable to xml. After spending some time in the newsgroups, i finally managed serializing, even with utf-8 instead of utf-16, which causes ie problems. But when deserializing the xml into the object structure, the following exception is beeing thrown: There is an error in XML document (3, 701).
3
8085
by: Chrigel | last post by:
Hi all, We have problems deseralizing objects previously serialized as XML. This did work fine with .NET 1.1 but since we have installed SP1, deserializing fails (but serializing works). The error occurs within the following line "return formatter.Deserialize(xmlReader) as ParameterList;" and the "innerexception" sais "The root element is missing.". Thanks for any hints
4
7510
by: Wayne Wengert | last post by:
Using VB.NET I want to read in an XML file that has an array of objects and then step through the resulting array in code. I build a class to define the structure and I am running code to read in the data but I can't figure out where the data is in the resulting array. Most of the relevant code is below. When I run the code to desrialize I get no errors but if I try to look at some of the data via the command window I get errors such as...
2
3093
by: Earl Teigrob | last post by:
I am saving and restoring value types such as Int32, DateTime and Boolean in strings. I was wondering if there is a mechanism build into .NET for serializing and deserializing these to string format. I can, of course, serialize a class to a file, either binary or XML, but this is not what I am looking for. Currently I am using ToString() or Convert.xxx to do this, but thought that if there was a true serializer, deserializer, that would be...
2
3767
by: Phillip Galey | last post by:
I have an object called Place which contains only string properties and has the <Serializable()> flag before the class name declaration. I also have a collection object called Places, which is implemented using Inherits System.Collections.Specialized.NameObjectCollectionBase and also has the <Serializable()> flag before the class name declaration. In the calling code, I'm successfully serializing the object to an XML file using a...
1
5826
by: RJN | last post by:
Hi I'm getting an error while deserializing an xml into object. System.Number.ParseDouble(String s, NumberStyles style, NumberFormatInfo info) +0 System.Double.Parse(String s, NumberStyles style, IFormatProvider provider) +208 System.Xml.XmlConvert.ToDouble(String s)
0
1884
by: RJN | last post by:
Hi I'm getting an error while deserializing an xml into object. System.Number.ParseDouble(String s, NumberStyles style, NumberFormatInfo info) +0 System.Double.Parse(String s, NumberStyles style, IFormatProvider provider) +208 System.Xml.XmlConvert.ToDouble(String s)
1
11792
by: =?Utf-8?B?SmVyZW15X0I=?= | last post by:
I am working on an order entry program and have a question related to deserializing nodes with nested elements. The purchase order contains multiple line items which I select using an XmlNodeList. I am trying to deserialize the nodes using a foreach as follows: foreach(XmlNode lineItem in LineItemsNodeList) An abbreviated example of the nested lineItem node looks like this:
2
2882
by: =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post by:
Hi, I know this will sound like a lot of hand waving, and I'll be glad to supply some sample code if necessary, but I thought something obvious might jump out at someone without doing so. Anyway, I have a structure that has several members including an array of strings. I assign the elements of the string array from the .Text property of several TextBoxes. I then serialize the structure and write it to a file. However, when I...
0
8674
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8604
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9028
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8895
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 most users, this new feature is actually very convenient. If you want to control the update process,...
1
6518
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3046
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.