I am trying the following in C#:
public class Reference : AuditableTable
{
[Range(0, 99, ErrorMessage = "{0} must be between {1} and {2}")]
[DisplayName("Order")]
public int Order {
get { return Order; }
set {
if ((value < 0) || (value > 99)) {
throw new Exception(string.Format("{0} must be between 0 and 99", value.ToString()));
} else {
Order = value;
}
}
}
Can someone help explain why this would give a stack overflow error when reading?
Your property is referencing itself, thus resulting in an infinite loop.
An obvious fix is to use a private field and expose it through your property: