473,903 Members | 3,373 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Positio n 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(File Name, FileMode.Open)
Dim streamLen As Integer = fStream.Length

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

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

Case PropSaver.FileF ormats.XML
Dim sFormatter As SoapFormatter = New SoapFormatter(N othing, New
StreamingContex t(StreamingCont extStates.File) )

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

End Select
fStream.Close()

End Sub
'Serialize
Private Sub DoSaveToFile(By Val FileName As String)

Dim file As System.IO.File

If (Not FileName Is Nothing) And (FileName.Lengt h > 0) Then
Dim fStream As System.IO.Strea m = file.Open(FileN ame, IO.FileMode.Cre ate)

Select Case FileFormat
Case PropSaver.FileF ormats.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.Seri alize(fStream, obj.value)
Next obj

Case PropSaver.FileF ormats.XML
Dim sFormatter As New SoapFormatter(N othing, New
StreamingContex t(StreamingCont extStates.File) )

'Deserialize the contents of the File Stream (me.InnerList)
Dim obj As Object
For Each obj In AllSettings 'AllSettings is a hashtable
sFormatter.Seri alize(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:TextBoxSett ings id="ref-1" >
<Text id="ref-3">Jack</Text>
<ControlName id="ref-4">TextBox1</ControlName>
<SettingType>Co ntrolSetting</SettingType>
<TypeName id="ref-5">TextBox</TypeName>
<ControlSetting sBase_x002B_mKe y
id="ref-6">Form1.TextBo x1</ControlSettings Base_x002B_mKey >
<ControlSetting sBase_x002B_mFo rmName
id="ref-7">Form1</ControlSettings Base_x002B_mFor mName>
<SettingsBase_x 002B_mKey id="ref-8"></SettingsBase_x0 02B_mKey>
<SettingsBase_x 002B_mFormName xsi:null="1"/>
</a1:TextBoxSetti ngs>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

<SOAP-ENV:Envelope ...>
<SOAP-ENV:Body>
<a1:FormSetting s id="ref-1" ...>
<Top>92</Top>
<Left>91</Left>
<Width>153</Width>
<Height>166</Height>
<WindowState>No rmal</WindowState>
<SaveWindowStat e>false</SaveWindowState >
<ControlName id="ref-4">Form1</ControlName>
<SettingType>Co ntrolSetting</SettingType>
<TypeName id="ref-5">Form</TypeName>
<ControlSetting sBase_x002B_mKe y
id="ref-6">Form1.For m1</ControlSettings Base_x002B_mKey >
<ControlSetting sBase_x002B_mFo rmName href="#ref-4"/>
<SettingsBase_x 002B_mKey id="ref-7"></SettingsBase_x0 02B_mKey>
<SettingsBase_x 002B_mFormName xsi:null="1"/>
</a1:FormSettings >
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>


Nov 20 '05 #1
0 1634

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

Similar topics

2
3124
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 ms As IO.MemoryStream = New IO.MemoryStream sf.Serialize(ms, currentIssue) ErrorReportingTextBox.Text &= vbCrLf &
1
1523
by: cjmumford | last post by:
I have a couple of C# objects like this: class Foo { } class Bar { Foo m_foo; Foo foo {
2
8353
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 the file. Only the public portions of the key are (you can see this by opening up the serialtest.xml file written). My question is: Am I just missing something very simple here or do I have to write a custom class to turn a RSAParameters into a...
6
3393
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
3528
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: + More ways to contact me __________________________________________________________________
1
1584
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' occurred in system.xml.dll Additional information: There was an error reflecting 'VestaQuoteV1.Case'.
1
2035
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 in mscorlib.dll Additional information: Exception has been thrown by the target of an invocation.
1
969
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 ms As IO.MemoryStream = New IO.MemoryStream sf.Serialize(ms, currentIssue) ErrorReportingTextBox.Text &= vbCrLf &
9
2076
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 if I try to deserialize with another different app, I get an exception (the assembly RegionViewer is the app that serialized the
0
9999
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
9849
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
11285
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10986
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,...
0
10501
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8049
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
7208
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
6094
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3324
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.