An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type enum Description
11,575
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";
}
}
Author by
adelphia
Updated on June 13, 2022Comments
-
adelphia almost 2 years
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 }
-
adelphia over 10 yearsThanks Adam. But I cannot find namespace StringResources. I created a resx file in VS and I see the xml format of the same: <data name="Status_0" xml:space="preserve"> <value>"Error: User action required. Expand row for details"</value> </data>
-
Adam Rackis over 10 yearsI think you may need to define these values differently. I don't think editing the code in the resx file is a good idea.