rhughes
rhughes

Reputation: 9583

Description attribute on Enum giving error

I am getting the following error from the description attribute as follows:

Attribute 'Description' is not valid on this declaration type. It is only valid on 'method' declarations.

public enum TestEnum
{
    [Description("Property 1")]
    Property1,
}

I have never had this error before and Google isn't shedding much light. I guess it is a reference issue, but I'm not really sure.

Upvotes: 4

Views: 4326

Answers (1)

Bradley Smith
Bradley Smith

Reputation: 13601

The DescriptionAttribute can be applied to virtually any type of member, including enum values. Are you sure you're using the right [Description]? Make sure you reference the assembly it comes from:

using System.ComponentModel;

And, if you do happen to have two different attributes called 'Description' in your scope, prefix it with the namespace to remove the ambiguity, i.e.

enum MyEnum {
    [System.ComponentModel.Description("Blah")]
    MyValue
}

Upvotes: 10

Related Questions