472,328 Members | 1,141 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Problem Serializing Multiple Objects to the Same Stream with SoapFormatter

I'm trying to serialize a collection to a file stream by serializing each object
individually. The code below works fine with the BinaryFormatter, but the
SoapFormatter reads the first object and just goes to the end of the file. After
reading the first object, the fStream.Position is pointed to the end of the file.
The collection serializes/deserilizes fine when I just serialize the hashtable vs.
each object in the hashtable.

Does anyone see anything wrong with the serialize/deserialize code below?

Thanks in Advance - JackRazz

'Deserialize
Private Sub DoLoadFromFile(ByVal FileName As String)
Dim file As System.IO.File

'Initilize
Dim obj As Object

'Open stream for Input
Dim fStream As FileStream = New FileStream(FileName, FileMode.Open)
Dim streamLen As Integer = fStream.Length

Select Case FileFormat
Case PropSaver.FileFormats.Binary
Dim bFormatter As New BinaryFormatter()

'Deserialize the contents of the File Stream (me.InnerList)
Do While fStream.Position < streamLen
obj = bFormatter.Deserialize(fStream)
Me.Add(obj)
Loop

Case PropSaver.FileFormats.XML
Dim sFormatter As SoapFormatter = New SoapFormatter(Nothing, New
StreamingContext(StreamingContextStates.File))

'Deserialize the contents of the File Stream (me.InnerList)
Do While fStream.Position < streamLen
obj = sFormatter.Deserialize(fStream)
Me.Add(obj)
Loop

End Select
fStream.Close()

End Sub
'Serialize
Private Sub DoSaveToFile(ByVal FileName As String)

Dim file As System.IO.File

If (Not FileName Is Nothing) And (FileName.Length > 0) Then
Dim fStream As System.IO.Stream = file.Open(FileName, IO.FileMode.Create)

Select Case FileFormat
Case PropSaver.FileFormats.Binary
Dim bFormatter As New BinaryFormatter()

'Deserialize the contents of the File Stream (me.InnerList)
Dim obj As Object
For Each obj In AllSettings
bFormatter.Serialize(fStream, obj.value)
Next obj

Case PropSaver.FileFormats.XML
Dim sFormatter As New SoapFormatter(Nothing, New
StreamingContext(StreamingContextStates.File))

'Deserialize the contents of the File Stream (me.InnerList)
Dim obj As Object
For Each obj In AllSettings 'AllSettings is a hashtable
sFormatter.Serialize(fStream, obj.value)
Next obj

End Select
fStream.Close()
End If

End Sub
Contents of xml file with 2 objects
-----------------------------------------------------------------------
<SOAP-ENV:Envelope >
<SOAP-ENV:Body>
<a1:TextBoxSettings id="ref-1" >
<Text id="ref-3">Jack</Text>
<ControlName id="ref-4">TextBox1</ControlName>
<SettingType>ControlSetting</SettingType>
<TypeName id="ref-5">TextBox</TypeName>
<ControlSettingsBase_x002B_mKey
id="ref-6">Form1.TextBox1</ControlSettingsBase_x002B_mKey>
<ControlSettingsBase_x002B_mFormName
id="ref-7">Form1</ControlSettingsBase_x002B_mFormName>
<SettingsBase_x002B_mKey id="ref-8"></SettingsBase_x002B_mKey>
<SettingsBase_x002B_mFormName xsi:null="1"/>
</a1:TextBoxSettings>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

<SOAP-ENV:Envelope ...>
<SOAP-ENV:Body>
<a1:FormSettings id="ref-1" ...>
<Top>92</Top>
<Left>91</Left>
<Width>153</Width>
<Height>166</Height>
<WindowState>Normal</WindowState>
<SaveWindowState>false</SaveWindowState>
<ControlName id="ref-4">Form1</ControlName>
<SettingType>ControlSetting</SettingType>
<TypeName id="ref-5">Form</TypeName>
<ControlSettingsBase_x002B_mKey
id="ref-6">Form1.Form1</ControlSettingsBase_x002B_mKey>
<ControlSettingsBase_x002B_mFormName href="#ref-4"/>
<SettingsBase_x002B_mKey id="ref-7"></SettingsBase_x002B_mKey>
<SettingsBase_x002B_mFormName xsi:null="1"/>
</a1:FormSettings>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>


Nov 20 '05 #1
0 1521

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

Similar topics

2
by: Scott Meddows | last post by:
I'm trying to serialize an object in VB.NET. I have all my objects denoted with the <Seralizable()> Attribute. This is the code I am using... ...
1
by: cjmumford | last post by:
I have a couple of C# objects like this: class Foo { } class Bar { Foo m_foo; Foo foo {
2
by: Eric | last post by:
Hello, I am wanting to serialize (for storage of an RSA Keypair) a RSAParameters class. It seems that even if i export the private portions of...
6
by: Rein Petersen | last post by:
Hi Folks! Here's a strange behaviour: Without a properties SET accessor (see code below), the property will not serialize. public class...
2
by: Tobias Zimmergren | last post by:
Hi, just wondering what serializing really is, and howto use it? Thanks. Tobias ...
1
by: Jax | last post by:
I have a rather large class that i'm looking to serialize to Xml. Whenever it tries to serialize it I get this error message: An unhandled...
1
by: Bsiang Tan | last post by:
I try to serialize my object into xml it work, but I can't deserialize it back. I get an exception.. :- An unhandled exception of type...
1
by: Scott Meddows | last post by:
I'm trying to serialize an object in VB.NET. I have all my objects denoted with the <Seralizable()> Attribute. This is the code I am using... ...
9
by: norvinl | last post by:
Hi, I'm serializing a class and using shared memory / deserialization to send it to other processes. I can serialize with one app and...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
1
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

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.