GetCustomAttributes APIs ignore an inherited "Inherited = false" specification - by Fabian Schmied

Status : 

  Won't Fix<br /><br />
		Due to several factors the product team decided to focus its efforts on other items.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.


1
0
Sign in
to vote
ID 779575 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 2/20/2013 12:33:41 AM
Access Restriction Public

Description

When a base custom attribute class BaseAttribute has an AttributeUsageAttribute specifying that it is not inheritable (Inherited = False) and a derived attribute class DerivedAttribute inherits from that base attribute class, the Type.GetCustomAttributes and Attribute.GetCustomAttributes APIs do not consider the inherited specification of non-inheritability.

Since the AttributeUsageAttribute is itself documented as being inherited (and indeed the ValidOn part of the AttributeUsage specification is, by the C# compiler, evaluated correctly), the DerivedAttribute does inherit the "Inherited = false" specification from its base class, and the GetCustomAttributes APIs should respect it.
Sign in to post a comment.
Posted by Atsushi [MSFT] on 3/11/2013 at 10:53 AM
Thank you for the feedback. This behavior does seem inconsistent - however, due to the risk of compatibility problems, we cannot change the behavior now. Your feedback will be passed along to documentation for a possible cite in MSDN.
Posted by Macy [MSFT] on 2/21/2013 at 10:14 PM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by Helen [MSFT] on 2/21/2013 at 1:50 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Posted by Fabian Schmied on 2/20/2013 at 12:35 AM
See also http://stackoverflow.com/questions/14955406/do-custom-attribute-classes-inherit-the-inherited-attributeusage-flag.

I'm aware that Microsoft will probably not fix this issue, since the risk of breaking existing applications would be too high. However, I'd hope that at least the documentation for AttributeUsageAttribute is changed to reflect the current semantics.