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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:10:17+00:00 2026-05-16T06:10:17+00:00

I have two classes, shown below: [Serializable] [XmlInclude(typeof(SomeDerived))] public class SomeBase { public string

  • 0

I have two classes, shown below:

[Serializable]
[XmlInclude(typeof(SomeDerived))]
public class SomeBase
{
    public string SomeProperty { get; set; }
}

public class SomeDerived : SomeBase
{
    [XmlIgnore]
    public new string SomeProperty { get; set; }
}

When I serialize and instance of SomeDerived I don’t expect to see a value for SomeProperty. However, I do. I’ve tried other approaches such as having SomeProperty declared as virtual in SomeBase and overriding it in SomeDerived. Still I see it in a serialized instance of SomeDerived.

Can anyone explain what is going on with the XmlIgnoreAttribute?

For completeness, my deserialization code is below

class Program
{
    static void Main(string[] args)
    {
        SomeDerived someDerived = new SomeDerived { SomeProperty = "foo" };

        XmlSerializer ser = new XmlSerializer(typeof(SomeBase));

        MemoryStream memStream = new MemoryStream();
        XmlTextWriter xmlWriter = new XmlTextWriter(memStream, Encoding.Default);
        ser.Serialize(memStream, someDerived);

        xmlWriter.Close();
        memStream.Close();
        string xml = Encoding.Default.GetString(memStream.GetBuffer());

        Console.WriteLine(xml);
        Console.ReadLine();
    }
}

Edit

I get the same behaviour if I change the serializer declaration to new XmlSerializer(typeof(SomeDerived)).

  • 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-16T06:10:17+00:00Added an answer on May 16, 2026 at 6:10 am

    Try this out. It uses the override on the XmlSerializer constructor to pass in some serialization overrides:

    SomeDerived someDerived = new SomeDerived { SomeProperty = "foo" };
    
    // Create the XmlAttributeOverrides and XmlAttributes objects.
    XmlAttributeOverrides overrides = new XmlAttributeOverrides();
    XmlAttributes attrs = new XmlAttributes();
    
    /* Use the XmlIgnore to instruct the XmlSerializer to ignore
        the GroupName instead. */
    attrs = new XmlAttributes();
    attrs.XmlIgnore = true;
    overrides.Add(typeof(SomeBase), "SomeProperty", attrs);
    
    XmlSerializer ser = new XmlSerializer(typeof(SomeBase), overrides);
    
    MemoryStream memStream = new MemoryStream();
    XmlTextWriter xmlWriter = new XmlTextWriter(memStream, Encoding.Default);
    ser.Serialize(memStream, someDerived);
    
    xmlWriter.Close();
    memStream.Close();
    string xml = Encoding.Default.GetString(memStream.GetBuffer());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two classes and an interface shown below. Quick summary: Interface Winterface, Class
I have two classes Foo and Bar that Bar extends Foo as below: class
I have two simple POCO classes; I'm trying to get the MyY property below
Imagine that I have two classes (shown below). Now imagine that I am compiling
I have two classes A and B. Class B inherits class A as shown
I have two classes, which reference the third: class Data1 { public Named Xxx
I have two classes (MVC view model) which inherits from one abstract base class.
I have two classes, one that inherits from the other. The base class is
I have two classes set up as follows: class Point { protected: double coords[3];
I have two classes, class A and class B. Class A has a mission

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.