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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:57:58+00:00 2026-05-29T09:57:58+00:00

I am trying to find the DataMember attribute on properties of a class. I

  • 0

I am trying to find the DataMember attribute on properties of a class. I can find the attribute if it is on a property defined directly in the class. However if the property is defined in a base class and overridden, the attribute is not found. I have found several links stating you have to use System.Attribute to get this information. Below is a direct quote from Microsoft.

Calling ICustomAttributeProvider.GetCustomAttributes on PropertyInfo or EventInfo when the inherit parameter of GetCustomAttributes is true does not walk the type hierarchy. Use System.Attribute to inherit custom attributes.

This seems to fix the problem completely when using the full framework. This seems to fix the problem for ONLY “non-system” attributes in Silverlight (tested on Silverlight 3.0, 4.0, 5.0). My sample code below shows that DataMemberAttribute is not returned while another custom defined Attribute is returned. Is this a bug or am I missing something?

public class CustomAttribute : Attribute
{
}

public class Animal 
{
    [DataMember(), CustomAttribute()]
    public virtual decimal Weight { get; set; }
}

public class Dog : Animal
{
    public override decimal Weight { get; set; }
}

public partial class MainPage : UserControl
{
    public MainPage()
    {
        InitializeComponent();
        var animalAttributes = Attribute.GetCustomAttributes(typeof(Animal).GetProperties()[0], true);
        var dogAttributes = Attribute.GetCustomAttributes(typeof(Dog).GetProperties()[0], true);
        //animalAttributes contains 2 entries (DataMember, CustomAttribute)
        //dogAttributes contains only 1 entry (CustomAttribute)
    }
}
  • 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-29T09:57:58+00:00Added an answer on May 29, 2026 at 9:57 am

    I think you have to set the AttributeUsage in you CustomAttribute to accept inheritance: http://msdn.microsoft.com/en-us/library/2ab31zeh.aspx

    Set the Inherited in AttributeUsage to true.

    EDITED

    The DataMemberAttribute, does not allows inheritance. http://msdn.microsoft.com/pt-br/library/system.runtime.serialization.datamemberattribute.aspx

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

Sidebar

Related Questions

I'm trying to implement a model(gfx) class but I can't seem to find a
Trying to find a standard. The CmdLet will process data - multiple input, defined
Trying to find examples of when decorators might be really beneficial, and when not
While trying to find an answer to Android Jasper Reporting I found out that
I am trying to create a Container class where I can retrieve an object
Trying to find the best way to dynamically add a direction attribute to each
I'm trying find software to view .img files. But its not expected. .img file
I am trying find out what is postgres can handle safely inside of transaction,
I am trying find all the users that are not in a friends user
Trying to find the min for this stack; however, whenever I run this in

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.