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

  • SEARCH
  • Home
  • 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 8727353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:25:18+00:00 2026-06-13T08:25:18+00:00

When I tried to serialize a generic list of objects, I get some data

  • 0

When I tried to serialize a generic list of objects, I get some data loss, with any of the variables that are used by the derived classes. I used to have those variables in the derived class, but since the base class was getting serialized I assumed the derived variables would get ignored.

The Code:

[XmlInclude(typeof(AchievementStock))]
    [XmlInclude(typeof(AchievementCash))]
    [XmlInclude(typeof(AchievementStockSpecify))]
    public abstract class Achievement : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
        protected string _title;
        protected string _description;
        protected int _cashValue;
        protected bool _completed;

        //Cash
        protected int _amountCash;
        protected bool _greater;

        //Stocks
        protected int _amountStocks;

        //StockSpecify
        protected string _stockName;
        protected int _amount;


        public abstract void CheckAchievement(AssetManager assetManager, AchievementManager achievementManager);

        public Achievement()
        {
        }

        public Achievement(string title, string description, int cashValue, bool completed)
        {
            Title = title;
            Description = description;
            _cashValue = cashValue;
            _completed = completed;
        }

        public void PropertyChangedEvent(string assetName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(assetName));
            }
        }

    }

    public class AchievementCash : Achievement
    {


        public AchievementCash(string title, string description, int cashValue, bool completed, int amountCash, bool greater)
            : base(title, description, cashValue, completed)
        {
            _amountCash = amountCash;
            _greater = greater;
        }

        public AchievementCash()
        {
        }

        public override void CheckAchievement(AssetManager assetManager, AchievementManager achievementManager)
        {


        }
    }

    public class AchievementStock : Achievement
    {


        public AchievementStock(string title, string description, int cashValue, bool completed, int amountStocks)
            : base(title, description, cashValue, completed)
        {
            _amountStocks = amountStocks;
        }

        public AchievementStock()
        {
        }

        public override void CheckAchievement(AssetManager assetManager, AchievementManager achievementManager)
        {
        }
    }

    public class AchievementStockSpecify : Achievement
    {
        public AchievementStockSpecify(string title, string description, int cashValue, bool completed, string stockName, int amount)
            : base(title, description, cashValue, completed)
        {
            _stockName = stockName;
            _amount = amount;
        }

        public AchievementStockSpecify()
        {
        }

        public override void CheckAchievement(AssetManager assetManager, AchievementManager achievementManager)
        {
        }
}

The variables that become default value are:

        //Cash
        protected int _amountCash;
        protected bool _greater;

        //Stocks
        protected int _amountStocks;

        //StockSpecify
        protected string _stockName;
        protected int _amount;

Anyone have any ideas on why this is occurring?

  • 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-13T08:25:19+00:00Added an answer on June 13, 2026 at 8:25 am

    You must have public fields rather than protected fields as only public properties and fields can be serialized by XMLSerializer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can I serialize a generic list of serializable objects without having to specify their
I have tried to serialize the class which contains the list of objects but
I want to be able to serialize/deserialize a generic list what I so far
I have some simple .NET objects I'd like to serialize to JSON and back
What is the most appropriate way to serialize Java Classes to XML? I tried
I wonder if there is any way to serialize to xml a class that
I tried to encode all values like encodeURIComponent($(#customer_details).serialize()); and that doesn't work as expected.
When trying to serialize a type (a generic List<T> which T is a class
I have tried to serialize data using XmlSerializer . I have found very a
I have some xml that is provided with generic attributes (name, type, etc), where

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.