| .NET DotNet Forum Index » .NET Framework Forum » Can't serialize ArrayList... |
|
Page 1 of 1 |
|
| Author |
Message |
| Steven... |
Posted: Mon Nov 02, 2009 9:47 am |
|
|
|
Guest
|
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 |
|
|
| Back to top |
|
|
|
| Peter Duniho... |
Posted: Mon Nov 02, 2009 1:52 pm |
|
|
|
Guest
|
Steven wrote:
Quote: 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 |
|
|
| Back to top |
|
|
|
| go... |
Posted: Tue Nov 03, 2009 6:53 am |
|
|
|
Guest
|
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:
Quote: 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
|
|
|
| Back to top |
|
|
|
|