Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type enum Description

Tags:

c#

.net

resx

I am trying to have the Description of an enum pulled from the resx file, but I get the above error.

Here is my code:

public enum FinalStatus
{
    [Description(StringResources.MyStrings.Status_0)]
    Error = 0,
    [Description(StringResources.MyStrings.Status_1)]
    Ok = 1,
    [Description(StringResources.MyStrings.Status_5)]
    Warning = 2,
    [Description(StringResources.MyStrings.Status_4)]
    Unknown = 3
}
like image 459
adelphia Avatar asked Oct 24 '13 23:10

adelphia


1 Answers

The error is correct; these values need to be constants. You'll need to change your Status_n definitions to something more like this:

namespace StringResources{
    public class MyStrings{
        public const string Status_0 = "0";
        public const string Status_1 = "1";
        public const string Status_4 = "4";
        public const string Status_5 = "5";
    }
}
like image 71
Adam Rackis Avatar answered Sep 18 '22 15:09

Adam Rackis