Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7818533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:36:28+00:00 2026-06-02T06:36:28+00:00

I want to deserialize back my class using System.Xml.Serialization, but i’ve noticed a strange

  • 0

I want to deserialize back my class using System.Xml.Serialization, but i’ve noticed a strange behaviour using List Properties:

it never calls the set method, which lead me to loosing vital informations …

I’d like to avoid to switch serialization method.

public class Category
{
    private string _name;
    private List<Category> _subCategories;
    private Category _parent;

    public string Name
    {
        get { return _name; }
        set { _name = value; }
    }

    public List<Category> SubCategories
    {
        get { return _subCategories; }
        set
        {
            _subCategories = value;
            foreach (Category category in _subCategories) 
            { 
                category.Parent = this; 
            }
        }
    }

    [System.Xml.Serialization.XmlIgnoreAttribute]
    public Category Parent
    {
        get { return _parent; }
        set { _parent = value; }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T06:36:29+00:00Added an answer on June 2, 2026 at 6:36 am

    Actually, the serializer does set the SubCategories property, but it sets it to an empty list, then adds items to the list. That’s why the Parent property of the children doesn’t get set. I wrote an article some time ago about XML serialization of parent/child relationships, you can find it here.

    Using the solution in that article, your Category class would look like this:

    public class Category : IChildItem<Category>
    {
        private string _name;
        private readonly ChildItemCollection<Category, Category> _subCategories;
        private Category _parent;
    
        public Category()
        {
            _subCategories = new ChildItemCollection<Category, Category>(this);
        }
    
        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }
    
        public ChildItemCollection<Category, Category> SubCategories
        {
            get { return _subCategories; }
        }
    
        [System.Xml.Serialization.XmlIgnoreAttribute]
        public Category Parent
        {
            get { return _parent; }
            set { _parent = value; }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to deserialize an object but don't know the class up front. So,
Using c#, I want to deserialize xml from various sources into objects of a
I'm using Python+PyAMF to talk back and forth with Flex clients, but I've run
I want to serialize an object to XML, but I don't want to save
want to know why String behaves like value type while using ==. String s1
Want the function to sort the table by HP but if duplicate HPs then
want to ask user to input something but not want to wait forever. There
I want to serialize/deserialize doubles to a readable String. I'm happy to lose any
A few days back I had to de-serialize data from xml file to my
I have a class with a map, and I want to serialize the class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.