views:

18

answers:

0

I am trying to make a small proof of concept example that employs validation for my model, using the System.ComponentModel.DataAnnotations namespace.

What I am trying to do here, is make sure that user input is between a specified range, using the supplied [Range] attribute.

I get a run-time exception that says Resolution of the dependency failed, type... or simply a ResolutionFailedException. If I exchange the [Range] attribute and use another one like [Required] it works and I get no run-time exception. So am I doing something wrong with the [Range] attribute? Here is my code below.

 private int myInt;
 //[Required(ErrorMessage = "This is Required")]
 [Range(18, 40, ErrorMessage = "Age must be 18 ~ 40")]
 public int MyInt
 {
    get { return this.myInt; }
    set
    {
       if (this.myInt != value)
       {
          Validator.ValidateProperty(value, new ValidationContext(this, null, null) { MemberName = "MyInt" });
          this.myInt = value;
          RaisePropertyChanged("MyInt"); // implementation of INotifyPropertyChanged
       }
    }
 }