Compiler Error CS0592
Visual Studio 2008
Updated: September 2008
Attribute 'attribute' is not valid on this declaration type. It is valid on 'type' declarations only.
When you define an attribute, you define what constructs it can be applied to by specifying an AttributeTargets value. In the following example, the MyAttribute attribute can be applied to interfaces only, because the AttributeUsage attribute specifies AttributeTargets.Iterface. The error is generated because the attribute is applied to a class (class A).