473,398 Members | 2,812 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,398 software developers and data experts.

Problems with Serialize/Deserialize... CODE BELOW

Every time i try to make Deserialize the computer gives me
the folowing error:
"End of Stream encountered before parsing was complete"

the code that i'm running is simple and is based on an
MSDN example. The CODE is BELOW this lines. If you see
something wrong or missing please answer.

Class declaration:

<Serializable()> Public Class MyO
Public n1 As Integer = 0
Public n2 As Integer = 0
Public str As String = String.Empty
End Class 'MyO
Code:

Dim objecto As New MyO()
Dim exp As New MyO()
Dim s As New System.IO.MemoryStream()
Dim formatter As New _
System.Runtime.Serialization. _
Formatters.Binary.BinaryFormatter()
objecto.n1 = 1
objecto.n2 = 2
objecto.str = "ola"

s.Capacity() = 256000
formatter.Serialize(s, objecto)

Try
exp = CType(formatter.Deserialize(s), MyO)
Catch erro As Exception
MessageBox.Show(erro.Message.ToString())
End Try
Nov 20 '05 #1
2 2409
"alexandre martins" <an*******@discussions.microsoft.com> wrote...
s.Capacity() = 256000
formatter.Serialize(s, objecto)
I'll guess that you need to rewind the stream...

s.Position = 0

Try
exp = CType(formatter.Deserialize(s), MyO)
Catch erro As Exception
MessageBox.Show(erro.Message.ToString())
End Try

Nov 20 '05 #2
alexandre,
Dim exp As New MyO()
exp = CType(formatter.Deserialize(s), MyO) I hope you realize you just "wasted" an object, if you are going to assign a
New object to a variable, you do not need to initialize the variable.

The following declares a MyO variable without initializing it. Dim exp As MyO
I believe your problem is that formatter.Serialize leaves the stream at the
"end of file", formatter.Deserialize then attempts to read from the "end of
file". Between the Serialize & Deserialize methods you should use the
Stream.Seek to set the Stream.Position property back to the "beginning of
the file".

Hope this helps
Jay
"alexandre martins" <an*******@discussions.microsoft.com> wrote in message
news:06****************************@phx.gbl... Every time i try to make Deserialize the computer gives me
the folowing error:
"End of Stream encountered before parsing was complete"

the code that i'm running is simple and is based on an
MSDN example. The CODE is BELOW this lines. If you see
something wrong or missing please answer.

Class declaration:

<Serializable()> Public Class MyO
Public n1 As Integer = 0
Public n2 As Integer = 0
Public str As String = String.Empty
End Class 'MyO
Code:

Dim objecto As New MyO()
Dim exp As New MyO()
Dim s As New System.IO.MemoryStream()
Dim formatter As New _
System.Runtime.Serialization. _
Formatters.Binary.BinaryFormatter()
objecto.n1 = 1
objecto.n2 = 2
objecto.str = "ola"

s.Capacity() = 256000
formatter.Serialize(s, objecto)

Try
exp = CType(formatter.Deserialize(s), MyO)
Catch erro As Exception
MessageBox.Show(erro.Message.ToString())
End Try

Nov 20 '05 #3

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

Similar topics

4
by: Wayne Wengert | last post by:
I am still stuck trying to create a Class to use for exporting and importing array data to/from XML. The format of the XML that I want to import/export is shown below as is the Class and the code I...
14
by: vince | last post by:
Can I add (append) to an xml file that already contains a serialized object, and be able to deserialize to either or both objects from the same file...??? How is this done...?? thanks, vince
5
by: David Sworder | last post by:
Hi, I've created a UserControl-derived class called MyUserControl that is able to persist and subsequently reload its state. It exposes two methods as follows: public void Serialize(Stream...
0
by: Mike Pollett | last post by:
Hi, I have used the ISerializable interface before and the code below worked fine. Until I derived it from CollectionBase. The code will still serialize and deserialize the properties in this class...
1
by: Mike Pollett | last post by:
Hi, I have used the ISerializable interface before and the code below worked fine. Until I derived it from CollectionBase. The code will still serialize and deserialize the properties in this class...
3
by: Jerry | last post by:
Hi, I have a class like the following: class A { private B _b; A (B b) { _b = b; } ...
1
by: Jim S | last post by:
I have an application where I have to make a tree of objects. To do this, I have my own node class. At certain points in the application, I need to save data. I am having a problem with the...
5
by: Brad | last post by:
I would like to serialize an arraylist of objects to xml so I can store the xml in a database column. How would I code the serializing and deserializing? Below is a (overly) simple, incomplete...
4
by: =?Utf-8?B?Qnlyb24=?= | last post by:
When I try to serialize an instance of the LocationCell below (note Building field) I get an error in the reflection attempt. If I remove the _Building field it serializes fine. I tried renaming...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...
0
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,...
0
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...

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.