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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:43:33+00:00 2026-05-13T21:43:33+00:00

Am I right in understanding the .NET XmlIgnoreAttribute , which says: Instructs the Serialize

  • 0

Am I right in understanding the .NET XmlIgnoreAttribute, which says:

Instructs the Serialize method of the XmlSerializer not to serialize the public field or public read/write property value.

that:

  • The property will be deserialized, if present in the XML file?
  • The property will not be serialized to a new XML file?

The reason I’m asking is that I have replaced a property in the file with a new one with more options. The old property was a simple boolean property, and the new one is an enum. I’ve changed the old property so that it converts the value of the new property into a boolean value, according to what the old property meant before I added the new one, both get and set has been implemented.

This allowed me to silently upgrade new files by reading the old property, which set the new property, and upon serialization, the new property was added.

However, I’d like to remove the old property from new xml files, so I was wondering what would happen if I tagged it with [XmlIgnore], would old xml file still deserialize properly and read that property from the file, or would it be ignored completely?

If not, would the following change do what I want?

[XmlAttribute("is-list")]
[DefaultValue(false)]
public bool IsList
{
    get { return false; }
    set {
        if (value)
            ListHandling = ListHandling.All;
    }
}

This would return false for all new objects, which would be ignored since I have specified a default value, and if present in an old file, and set to true, that would change the ListHandling property, which is the new one that is important.

Edit: Upon testing, I have verified that both approaches seems to do what I want. I’ll leave the question though, as I would still like to know if the first behaviour noted above is just an implementation detail, or if the documentation can be understood that way.

  • 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-13T21:43:34+00:00Added an answer on May 13, 2026 at 9:43 pm

    If you tag a property with XmlIgnore, it is ignored. It is not considered when the XmlSerializer builds its serialisation assembly. Therefore, XmlIgnore-d properties are not populated during deserialisation, and will be left with their default value.

    Sample program (for Snippet Compiler):

    public static void RunSnippet()
    {
      XmlSerializer ser = new XmlSerializer(typeof(Fie));
      Fie f = (Fie)(ser.Deserialize(new StringReader("<Fie><Bob>Hello</Bob></Fie>")));
      WL(f.Bob == null ? "null" : "something");
    }
    
    public class Fie
    {
      [XmlIgnore]
      public string Bob { get; set; }
    }
    

    The output from this program is null (and if you remove XmlIgnore from Fie.Bob the output is something).

    Edit in response to your edit: This is not just an implementation detail; it is indeed the documented behaviour of the attribute. From the Remarks section of the docs (first paragraph): “If you apply the XmlIgnoreAttribute to any member of a class, the XmlSerializer ignores the member when serializing or deserializing an instance of the class.” (emphasis added)

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

Sidebar

Related Questions

Just asking if I have the right understanding System.out.println(); System is the package out
Am I right in understanding the principles of DAO & Service layer interconnection? DAO
Right now I have an upload field while uploads files to the server. The
Right now, I've just some code which fetches the picture from the URL directly.
My understanding is, that .NET doesn't really 'do' config files for DLLs - only
I'm writing an app to get a better understanding of DKIM. The spec says
I am working on an ASP.Net MVC3 application and I'm having trouble understanding the
Perhaps this is a naive question. In my understanding, ASP.NET MVC cannot work with
I have a variation of the benefits-of-async/await-on-ASP.NET from this question . My understanding is
Explanation of the problem: Right now my asp.net mvc 3 application is using cookieles=auto

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.