473,411 Members | 1,949 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,411 software developers and data experts.

problem deserialization serialization

Hi,

if have a object arrSdList of type SortedList for serialization and
deserialization
there are two subs for doing this

Public Sub deser
Dim Formatter As BinaryFormatter = New BinaryFormatter()
Dim ReadFile As FileStream
ReadFile = File.OpenRead(FilePad)
arrSdList = CType(Formatter.Deserialize(ReadFile), SortedList)
ReadFile.Close()
End Sub

Public Sub ser
Dim Formatter As BinaryFormatter = New BinaryFormatter()
Dim SaveFile As FileStream
SaveFile = File.OpenWrite(FilePad)
SaveFile.Seek(0, SeekOrigin.End)
Formatter.Serialize(SaveFile, arrSdList)
SaveFile.Close()
End Sub

when i do
ser
deser
there is no exception message

but when i do
ser
deser
ser
i get the exception message for the second ser :

Binary stream does not contain a valid BinaryHeader, 0 possible causes,
invalid stream or object version change between serialization and
deserialization.

what is wrong with the subs ?
who can help me ?

Nov 20 '05 #1
2 1756
Info for the question
As value for the arrSdList i have a class instance defined as

<serializable> public class clsPerson
"andreas" <an*****@pandora.be> schreef in bericht
news:YL*********************@phobos.telenet-ops.be...
Hi,

if have a object arrSdList of type SortedList for serialization and
deserialization
there are two subs for doing this

Public Sub deser
Dim Formatter As BinaryFormatter = New BinaryFormatter()
Dim ReadFile As FileStream
ReadFile = File.OpenRead(FilePad)
arrSdList = CType(Formatter.Deserialize(ReadFile), SortedList)
ReadFile.Close()
End Sub

Public Sub ser
Dim Formatter As BinaryFormatter = New BinaryFormatter()
Dim SaveFile As FileStream
SaveFile = File.OpenWrite(FilePad)
SaveFile.Seek(0, SeekOrigin.End)
Formatter.Serialize(SaveFile, arrSdList)
SaveFile.Close()
End Sub

when i do
ser
deser
there is no exception message

but when i do
ser
deser
ser
i get the exception message for the second ser :

Binary stream does not contain a valid BinaryHeader, 0 possible causes,
invalid stream or object version change between serialization and
deserialization.

what is wrong with the subs ?
who can help me ?

Nov 20 '05 #2
Here is the code I am using. It looks roughly the same as yours. Haven't
actually tried calling ser, deser, ser again, so it may behave the same.
Give it a shot.

HTH,
Greg
Public Shared Function LoadSettings() As UserSettings

Dim mySettings As New UserSettings

Dim s As String =
Environment.GetFolderPath(System.Environment.Speci alFolder.ApplicationData)

s &= "\PCO\pco.bin"

If File.Exists(s) Then

Dim streamOut As FileStream

Try
Dim formatter As New BinaryFormatter

streamOut = New FileStream(s, FileMode.Open,
FileAccess.Read)

mySettings = CType(formatter.Deserialize(streamOut),
UserSettings)

Catch

Finally
streamOut.Close()
End Try
End If

Return mySettings

End Function

Public Shared Sub SaveSettings(ByVal mySettings As UserSettings)
Dim s As String =
Environment.GetFolderPath(System.Environment.Speci alFolder.ApplicationData)

s &= "\PCO"

If Not Directory.Exists(s) Then

Directory.CreateDirectory(s)

End If

s &= "\pco.bin"

Dim formatter As New BinaryFormatter

Dim streamIn As New FileStream(s, FileMode.Create,
FileAccess.Write)

formatter.Serialize(streamIn, mySettings)

streamIn.Close()

End Sub
"andreas" <an*****@pandora.be> wrote in message
news:IT**********************@phobos.telenet-ops.be...
Info for the question
As value for the arrSdList i have a class instance defined as

<serializable> public class clsPerson
"andreas" <an*****@pandora.be> schreef in bericht
news:YL*********************@phobos.telenet-ops.be...
Hi,

if have a object arrSdList of type SortedList for serialization and
deserialization
there are two subs for doing this

Public Sub deser
Dim Formatter As BinaryFormatter = New BinaryFormatter()
Dim ReadFile As FileStream
ReadFile = File.OpenRead(FilePad)
arrSdList = CType(Formatter.Deserialize(ReadFile), SortedList)
ReadFile.Close()
End Sub

Public Sub ser
Dim Formatter As BinaryFormatter = New BinaryFormatter()
Dim SaveFile As FileStream
SaveFile = File.OpenWrite(FilePad)
SaveFile.Seek(0, SeekOrigin.End)
Formatter.Serialize(SaveFile, arrSdList)
SaveFile.Close()
End Sub

when i do
ser
deser
there is no exception message

but when i do
ser
deser
ser
i get the exception message for the second ser :

Binary stream does not contain a valid BinaryHeader, 0 possible causes,
invalid stream or object version change between serialization and
deserialization.

what is wrong with the subs ?
who can help me ?


Nov 20 '05 #3

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

Similar topics

2
by: Snowman | last post by:
Suppose I have a RootObject which holds a collection of other objects. The other objects have a property (Parent) which refers back to the "parent" collection (b.t.w. my collection is based on...
4
by: Mike Sarbu | last post by:
Hello all, I have an XML file like this: <?xml version="1.0" encoding="utf-8"?> <SomeObject xmlns="http://www.abcinc.com/objectdefinition"...
1
by: andrewcw | last post by:
There is an error in XML document (1, 2). I used XML spy to create the XML and XSD. When I asked to have the XML validated it said it was OK. I used the .net SDK to generate the class. I have...
3
by: Amadelle | last post by:
Hi all and thanks in advance for your help, I am having problems deserializing an object which seems to be serializing just fine. I save the byte array of the serialized object in the database...
3
by: AnkitAsDeveloper [Ankit] | last post by:
Hi i am serializing a 'ref struct' object as follows : private: void Seri( String ^path, Object^ obj ) { FileStream^ fileStrm ; try { //Serialize entire object into Binary stream
8
by: ashoksrini | last post by:
Hi All, I have the below requirement and would like to get some feeback from the group on the best way to implement: 1. I have WSDL defined exposing few web services. 2. We dont have a...
0
by: Miguel RS | last post by:
Hi all, I have a winforms app (app1), a webservice (ws1) and a webpage (wp1). The webservice exposes a type (type1). When I generate a proxy (px1) for app1 I get the type ws1.type1. The thing is...
12
by: yoshijg | last post by:
Is there a way to be notified when the deserialization of an XML is complete, like a callback method? I tried the IDeserializationCallback interface, but that doesnt for XML-Deserialization. ...
5
by: Harold Howe | last post by:
I am having a problem deserializing objects from a library when the following conditions exist: 1- The library is strongly named 2- The serialized file was created with version 1.0 of the...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
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...
0
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...

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.