Given the following enum:
public enum SomeEnumType : byte
{
[Display(Name = "Name of EnumItemOne")]
EnumItemOne = 1,
[Display(Name = "Name of EnumItemTwo")]
EnumItemTwo = 2,
[Display(Name = "Name of EnumItemThree")]
EnumItemThree = 3,
}
I would like to use the maximal number of this enum in a data annotation (to validate the input values) using the solution from the following question: "Getting the max value of an enum"
[DisplayName("Some display name")]
[Range(1, Convert.ToInt32(Enum.GetValues(typeof(SomeEnumType)).Cast<SomeEnumType>().Max()), ErrorMessage = "Please choose an item")]
public SomeEnumType SomeField{ get; set; }
but I get the following error message:
Error CS0182 An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type
I do not have any idea about the root cause. Has someone faced error message like this?