The attribute argument must be a constant expression, a type expression, or an expression of an array expression of the attribute parameter type enum

I am trying to get a description of an enum extracted from a resx file, but I am getting 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 } 
+7
c # resx
source share
1 answer

The error is correct; these values ​​must be constant. You will need to change the Status_n definitions to the following:

 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"; } } 
+7
source share

All Articles