473,387 Members | 1,540 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,387 software developers and data experts.

Serializing/Deserializing an array.

I have some code that serializes an array of objects:

XmlSerializer serializer = new XmlSerializer(typeof(Purchase[]));
XmlTextWriter w = new XmlTextWriter("vpurchase.xml", Encoding.UTF8);
serializer.Serialize(w, purchaseArray);

This gives me something like:

<ArrayOfPurchase>
<Purchase> . . . </Purchase>
<Purchase> . . . </Purchase>
</ArrayOfPurchase>

Now if I try to deserialize the file with:

XmlSerializer serializer = new XmlSerializer(typeof(Purchase));
XmlTextReader r = new XmlTextReader("vpurchase.xml");
Purchase [] purchaseArray = (Purchase [])serializer.Deserialize(r);

I get an error. Exception is thrown InvalidOperation. Somehow my theory is
that the <ArrayOfPurchase> token is not being recognized properly in
deserialization. How can I get this to work bidirectionallly?

Thank you.

Kevin
Nov 12 '05 #1
1 1276
Try XmlSerializer serializer = new XmlSerializer(typeof(Purchase[])); as
above...
"Kevin Burton" <Ke*********@discussions.microsoft.com> schrieb im
Newsbeitrag news:03**********************************@microsof t.com...
I have some code that serializes an array of objects:

XmlSerializer serializer = new XmlSerializer(typeof(Purchase[]));
XmlTextWriter w = new XmlTextWriter("vpurchase.xml", Encoding.UTF8);
serializer.Serialize(w, purchaseArray);

This gives me something like:

<ArrayOfPurchase>
<Purchase> . . . </Purchase>
<Purchase> . . . </Purchase>
</ArrayOfPurchase>

Now if I try to deserialize the file with:

XmlSerializer serializer = new XmlSerializer(typeof(Purchase));
XmlTextReader r = new XmlTextReader("vpurchase.xml");
Purchase [] purchaseArray = (Purchase [])serializer.Deserialize(r);

I get an error. Exception is thrown InvalidOperation. Somehow my theory is
that the <ArrayOfPurchase> token is not being recognized properly in
deserialization. How can I get this to work bidirectionallly?

Thank you.

Kevin

Nov 12 '05 #2

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

Similar topics

3
by: Don McNamara | last post by:
Hi, I've hit quite a strange problem with XmlSerializer on my W2K3 server. When I serialize/deserialize using an exe on my local computer (XP), everything works fine. When I put the code out on...
5
by: Alfonso Morra | last post by:
Hi, I am writing a messaging library which will allow me to send a generic message structure with custom "payloads". In many cases, a message must store a non-linear data structure (i.e....
2
by: Earl Teigrob | last post by:
I am saving and restoring value types such as Int32, DateTime and Boolean in strings. I was wondering if there is a mechanism build into .NET for serializing and deserializing these to string...
5
by: Mark Saccomandi | last post by:
Hi, I'm extending a serializable class I made. The new class adds some features that cannot be serialized automatically, this means that I have to implement the ISerializable interface for my...
3
by: MioTheGreat | last post by:
I know how to take a single hashtable, and then use a binaryformatter and a filestream to dump it to a file, but I need to serialize and deserialize a hashtable inside a class. I've been trying...
0
by: Michael Maercker | last post by:
Hi! I'm about to go nuts over my serializing problem. This is my situation: I have a Data-Class that can have children of the same class which are stored in a hashtable, i.e: X has A as a...
0
by: j.askey | last post by:
Hi, I have a class that is inherited from Panel. Because Panel is not serializable, I have implemented the ISerializable interface on this class and I can sucessfully save and load classes from...
7
by: fjlaga | last post by:
I have written an Office Add-in for Excel using VB.NET and the .NET 1.1 Framework (I have Visual Studio 2003 .NET ). All works great. I want to add a User Settings/Prefereneces dialog and allow...
2
by: =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post by:
Hi, I know this will sound like a lot of hand waving, and I'll be glad to supply some sample code if necessary, but I thought something obvious might jump out at someone without doing so. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
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
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
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
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...

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.