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 6391951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:45:02+00:00 2026-05-25T03:45:02+00:00

I am new to XML serialization and I have read that private variables cannot

  • 0

I am new to XML serialization and I have read that private variables cannot be serialized until they are given under a public property. But while debugging after deserializing I am able to find the private variables also in the deserialized object. Can someone explain this? Here is my code:

class Program
{
    static void Main(string[] args)
    {
        XmlSerializer xs = new XmlSerializer(typeof(Nokia));
        Nokia n = new Nokia();

        using (Stream s = new FileStream("XMLFile", FileMode.Create, FileAccess.Write, FileShare.None))
        {
            xs.Serialize(s, n);
        }

        XmlSerializer xs1 = new XmlSerializer(typeof(Nokia));
        using (Stream ds = File.OpenRead("XMLFile"))
        {
            Nokia dn = (Nokia)xs1.Deserialize(ds);
        }
    }
}

public class Mobile
{
    public int Height = 10;
    private int weight = 20;
    public Mobile() {}
}

public class Nokia : Mobile
{
    public string Signal = "Poor";
    public Nokia() {}
}

While debugging when I quick watch my object after deserialization I am able to find the variable weight in the base. How is it possible? Or am I wrong somewhere else?

  • 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-05-25T03:45:03+00:00Added an answer on May 25, 2026 at 3:45 am

    The private variables will still exist in the deserialized object, but their values will not be stored in the XML serialized version.

    To demonstrate this, if you create an instance of your object, change the weight value then serialize it to XML. If you deserialize it, the value of weight in the deserialized object will be the default value, rather than the value set on the original object.

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

Sidebar

Related Questions

I have a loop in a BackgroundWorker that saves some stuff via xml Serialization
I have an XML document: var xml:XML = new XML(<rootNode> <head> <meta name=template content=Default
still new to XML parsing with the iphone so i have a few questions.
[TestInitialize()] public void MyTestInitialize() { XmlTextWriter writer = new XmlTextWriter(DataFile.xml, Encoding.UTF8); writer.Formatting = Formatting.Indented;
I have the following XML Parsing code in my application: public static XElement Parse(string
I have a web service that returns a simple object: [System.CodeDom.Compiler.GeneratedCodeAttribute(System.Xml, 2.0.50727.4927)] [System.SerializableAttribute()] [System.Diagnostics.DebuggerStepThroughAttribute()]
I am new to xml's. I have used xsd.exe to create a .xsd file
I've got some very large XML files which I read using a System.Xml.Serialization.XmlSerializer .
I have a simple console application that is designed to read a custom Configuration
I have a model that I would like to serialize to an xml with

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.