PC Review


Reply
Thread Tools Rate Thread

Can't serialize ArrayList

 
 
Steven
Guest
Posts: n/a
 
      2nd Nov 2009
Hi guys

I'm trying to serialize a class that includes an ArrayList member. Here's
the class:

[Serializable]
public class InstantiationData
{
public string InstanceTaskAssignedTo;
public string InstanceMailMsg;
public DateTime InstanceDueDate;
public Approvers ADApproversGroup; // this is the ArrayList member //
}

All other members of this class serialize properly, but the Approvers member
(a class which implements IEnumerator) does not. I've set a breakpoint
immediately after the Serialize method is called and inspected the object
which looks like this:

<?xml version="1.0" ?>
<InstantiationData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<InstanceTaskAssignedTo>cs_ap</InstanceTaskAssignedTo>
<InstanceMailMsg>Test message</InstanceMailMsg>
<InstanceDueDate>2009-11-09</InstanceDueDate>
<ADApproversGroup />
</InstantiationData>

As you can see, the ADApproversGroup node is empty when serialized, but the
class instance shows 2 elements in the arrayList.

I've read that when serializing, it helps to specify the type of object I'm
serializing which I've done as follows:

XmlSerializer serializer = new XmlSerializer(typeof(InstantiationData));

But this doesn't help. Any ideas how to serialize an ArrayList member of a
class?

Tks




 
Reply With Quote
 
 
 
 
Peter Duniho
Guest
Posts: n/a
 
      2nd Nov 2009
Steven wrote:
> Hi guys
>
> I'm trying to serialize a class that includes an ArrayList member. Here's
> the class:
>
> [Serializable]
> public class InstantiationData
> {
> public string InstanceTaskAssignedTo;
> public string InstanceMailMsg;
> public DateTime InstanceDueDate;
> public Approvers ADApproversGroup; // this is the ArrayList member //
> }


If it's an ArrayList member, why is the type "Approvers"?

It's practically impossible to say without a concise-but-complete code
example. But, it should be obvious that to serialize a member of a
class, that member needs to be serializable, and if it's a collection,
the collection members need to be serializable.

Whether those are _sufficient_ conditions in your case, I can't say.
But for sure, they are necessary.

Pete
 
Reply With Quote
 
go
Guest
Posts: n/a
 
      3rd Nov 2009
Hello Steven. Always when I want to serialize a type I start with
creating an xml-schema for the type and then (auto-)generate the
classes. I think it saves time and trouble.
///M

Steven skrev:
> Hi guys
>
> I'm trying to serialize a class that includes an ArrayList member. Here's
> the class:
>
> [Serializable]
> public class InstantiationData
> {
> public string InstanceTaskAssignedTo;
> public string InstanceMailMsg;
> public DateTime InstanceDueDate;
> public Approvers ADApproversGroup; // this is the ArrayList member //
> }
>
> All other members of this class serialize properly, but the Approvers member
> (a class which implements IEnumerator) does not. I've set a breakpoint
> immediately after the Serialize method is called and inspected the object
> which looks like this:
>
> <?xml version="1.0" ?>
> <InstantiationData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:xsd="http://www.w3.org/2001/XMLSchema">
> <InstanceTaskAssignedTo>cs_ap</InstanceTaskAssignedTo>
> <InstanceMailMsg>Test message</InstanceMailMsg>
> <InstanceDueDate>2009-11-09</InstanceDueDate>
> <ADApproversGroup />
> </InstantiationData>
>
> As you can see, the ADApproversGroup node is empty when serialized, but the
> class instance shows 2 elements in the arrayList.
>
> I've read that when serializing, it helps to specify the type of object I'm
> serializing which I've done as follows:
>
> XmlSerializer serializer = new XmlSerializer(typeof(InstantiationData));
>
> But this doesn't help. Any ideas how to serialize an ArrayList member of a
> class?
>
> Tks
>
>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Thread-safety: Change property of items in arraylist versus removingitems from the arraylist Curious Microsoft Dot NET 2 6th Aug 2008 12:36 PM
How to access ArrayList values inside another ArrayList? Pavel Maly Microsoft C# .NET 6 30th Oct 2006 01:46 PM
ArrayList(ICollection) constructor & overriden ArrayList.AddRange(). Sylvain Microsoft C# .NET 1 4th Jun 2005 01:19 AM
serialize to SQL Server Blob instead of XML serialize Gordz Microsoft ASP .NET 3 7th Jun 2004 08:46 PM
How to xml serialize arraylist of objects? Brad Microsoft VB .NET 5 5th Mar 2004 05:58 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:53 AM.