473,396 Members | 2,111 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.

Serialization Question

I realize that this is a newbie question but maybe someone will be able to
tell me what am I doing wrong.
createFile() gets called each time I have the user generate some numbers
which then get added to the binlist ArrayList.
I'm able to serialize and deserialize the Arraylist. However, when I
deserialize the ArrayList, it will only show the first set of ints. I
looked at the bin file and it does get appended to each time. Any help will
be appreciated.
Rich

private void createFile()
{
foreach (int a in num)
{
binlist.Add (a);
}

Stream streamAppend = File.Open("Numbers.bin",FileMode.Append);
bf.Serialize (streamAppend,binlist);
streamAppend.Close ();
Stream streamRead = File.OpenRead("Numbers.bin");
binlist=(ArrayList)bf.Deserialize (streamRead);
streamRead.Close ();
MessageBox.Show (binlist.Count .ToString ());
for(int i = 0; i < binlist.Count ; i ++)
{
MessageBox.Show (binlist[i].ToString ());
}
Nov 16 '05 #1
1 1565
Serialization does not support appending (at least not that I have read
anywhere, MSDN does not explicitly say this, but given how serialization
works, I can't imagine that it does work).

If you need to modify a serialized component, then you should deserialize it
first, then make your changes and then serialize it back, overwriting the
original file.

--
HTH

Kyril Magnos

Question of the day:
What is Mono?
A) Disease where the lymph nodes become swollen.
B) A single sound
C) A synonym for one
D) A port of .NET meant to royally irritate MSFT
E) All of the above.

"Silesian" <no****@spamthis.com> wrote in message
news:10*************@corp.supernews.com...
|I realize that this is a newbie question but maybe someone will be able to
| tell me what am I doing wrong.
| createFile() gets called each time I have the user generate some numbers
| which then get added to the binlist ArrayList.
| I'm able to serialize and deserialize the Arraylist. However, when I
| deserialize the ArrayList, it will only show the first set of ints. I
| looked at the bin file and it does get appended to each time. Any help
will
| be appreciated.
| Rich
|
| private void createFile()
| {
| foreach (int a in num)
| {
| binlist.Add (a);
| }
|
| Stream streamAppend = File.Open("Numbers.bin",FileMode.Append);
| bf.Serialize (streamAppend,binlist);
| streamAppend.Close ();
| Stream streamRead = File.OpenRead("Numbers.bin");
| binlist=(ArrayList)bf.Deserialize (streamRead);
| streamRead.Close ();
| MessageBox.Show (binlist.Count .ToString ());
| for(int i = 0; i < binlist.Count ; i ++)
| {
| MessageBox.Show (binlist[i].ToString ());
| }
|
|
Nov 16 '05 #2

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

Similar topics

16
by: Bob Rock | last post by:
Hello, when serializing an array of elements of a class Classname using XmlSerializer.Serialize() I get an XML like the following: <?xml version="1.0"> <ArrayOfClassname> ....... ..........
3
by: Aaron Clamage | last post by:
Hi, I'm not sure that if this is the right forum, but any help would be greatly appreciated. I am porting some java serialization code to c# and I can't figure out the correct way to do it. ...
5
by: francois | last post by:
First of all I would to to apologize for resending this post again but I feel like my last post as been spoiled Here I go for my problem: Hi, I have a webservice that I am using and I would...
6
by: Uttam | last post by:
Hello, We are at a very crucial decision making stage to select between .Net and Java. Our requirement is to download a class at runtime on the client computer and execute it using remoting or...
0
by: eSapient | last post by:
I generated serialization/deserialization code for this schema using the xsd tool: <?xml version="1.0" encoding="UTF-8"?> <xs:schema elementFormDefault="qualified"...
6
by: John Glover | last post by:
I'm having a very strange problem with XML serialization. I'm writing web services which pass instances of various classes back and forth as parameters and return values of web methods. The...
15
by: Jacques | last post by:
Hi I am an dotNet newby, so pardon my ignorance. I am looking for a method of saving/copying a managed class to a stream/file WITHOUT saving the object's state, eg. if I have a ref class with...
0
by: groovyghoul | last post by:
Hi I have the following XML file: =========================================================== <?xml version="1.0" encoding="UTF-16"?> <Policy xmlns="http://tempuri.org/richard.xsd"> <TransType...
0
by: nobin01 | last post by:
Dear sir; I want ur Help in serialization.I know serialization.I Know binary,soap and xmlserialization also.But i want ur help in following topics.pls help me as soon as possible.I have search in...
2
by: mkvenkit.vc | last post by:
Hello, I hope this is the right place to post a question on Boost. If not, please let me know where I can post this message and I will do so. I am having a strange problem with std::string as...
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: 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
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
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...

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.