473,785 Members | 2,457 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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("Numb ers.bin",FileMo de.Append);
bf.Serialize (streamAppend,b inlist);
streamAppend.Cl ose ();
Stream streamRead = File.OpenRead(" Numbers.bin");
binlist=(ArrayL ist)bf.Deserial ize (streamRead);
streamRead.Clos e ();
MessageBox.Show (binlist.Count .ToString ());
for(int i = 0; i < binlist.Count ; i ++)
{
MessageBox.Show (binlist[i].ToString ());
}
Nov 16 '05 #1
1 1585
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****@spamthi s.com> wrote in message
news:10******** *****@corp.supe rnews.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("Numb ers.bin",FileMo de.Append);
| bf.Serialize (streamAppend,b inlist);
| streamAppend.Cl ose ();
| Stream streamRead = File.OpenRead(" Numbers.bin");
| binlist=(ArrayL ist)bf.Deserial ize (streamRead);
| streamRead.Clos e ();
| 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
9550
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> ....... ....... </ArrayOfClassname>
3
3176
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. It seems that either I can use default serialization or implement ISerializable. Is there any way to do both (e.g. extend the default serialization). In other words, I want to be able to implement my custom serialization code but call the...
5
2831
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 like it to return an XML serialized version of an object.
6
2717
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 rmi. Just to keep my question short I am posting trimmed version of my code. //file: Serializable.cs
0
1722
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" attributeFormDefault="unqualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:complexType name="FAAAvxType"> <xs:sequence> <xs:choice>
6
6055
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 problem is that in my derived classes, the XML that is automatically generated is lacking the properties of the base class. For example: public class MyBaseClass { public MyBaseClass ( ) { } private string myVariable;
15
2412
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 two int32's as its data members, the binary file of that class must have a size of 8 bytes (i.e. only contains class data members, not methods etc.). Is serialization the answer to the above problem? If I understand correctly, the reason that...
0
1809
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 /> <LOB /> <Name> <FirstName />
0
1203
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 site but only basics serialization is there. Topics: 1) serialize a nested object in mutiple files by maintaining the relation on parent level. ie, let say object1 containts object2 and object2 contains object3 , while serializing the object1,...
2
5568
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 I am trying to read from a binary archive using Boost serialization. I am new to this, and it is possible that I have not understood the usage. In the code below, the string "faultblock" seems to be causing the problem. The code crashes in the ia...
0
9645
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
10325
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...
0
10147
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10091
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
9950
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...
0
6739
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();...
1
4050
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
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.