gln
gln

Reputation: 1031

C# serialisation problem

This is a class in a c# application:

[Serializable()] 
public class AAA
{
    private List<AAA> arr;
    private AAA parentA;

    public List<AAA> Arr
    {
        get { return arr; }
        set { arr = value; }
    }

    public AAA ParentA        
    {
        get { return parentA; }
        set { parentA = value; }
    }
 }

when I try to serialize this class by XMLSerializer and the list "arr" or "parentA" are containing a value the serialization fail to write the XML.

Can you please uggest a way how to resolve it?

Please attach code example.

Note: I must use XMLSerializer, Not any other serializer.

10x

Upvotes: 1

Views: 139

Answers (2)

Chojny
Chojny

Reputation: 170

add to the class attribute

[XmlInclude(typeof(AAA))] public class AAA

and public field like

[XmlArray("AAAarray")] [XmlArrayItem("Param", typeof(AAA))] public IList arr { get; set; }

Upvotes: 1

djeeg
djeeg

Reputation: 6765

Missing attribute? And the variable might have to be public.

[Serializable()]
public class AAA {
    public List<AAA> arr;
    public AAA parentA;
}

Upvotes: 2

Related Questions