Home Dashboard Directory Help
Search

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


Status: 

Closed
 as Won't Fix Help for as Won't Fix


1
0
Sign in
to vote
Type: Bug
ID: 779575
Opened: 2/20/2013 12:33:41 AM
Access Restriction: Public
0
Workaround(s)
view
0
User(s) can reproduce this bug

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.
Details
Sign in to post a comment.
Posted by Microsoft 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 Microsoft 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 Microsoft 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.
Sign in to post a workaround.