473,396 Members | 1,970 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,396 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 1595

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... Dim sf As SoapFormatter = New SoapFormatter Dim...
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 the Key, they are never serialized and stored in...
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 myObject {
2
by: Tobias Zimmergren | last post by:
Hi, just wondering what serializing really is, and howto use it? Thanks. Tobias __________________________________________________________________ Tobias ICQ#: 55986339 Current ICQ status: +...
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 exception of type 'System.InvalidOperationException'...
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 'System.Reflection.TargetInvocationException' occurred...
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... Dim sf As SoapFormatter = New SoapFormatter Dim...
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 deserialize with another instance of the same app. But...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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:
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...

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.