title: Understanding ValidationContext in DataAnnotations
body: <p>I want to utilize <code>Validator.TryValidateValue()</code> but don't understand the mechanics. Say, i have the following:</p>
  
  <pre><code>public class User {
      [Required(AllowEmptyStrings = false)]
      [StringLength(6)]
      public string Name { get; set; }
  }
  </code></pre>
  
  <p>and the method:</p>
  
  <pre><code>public void CreateUser(string name) {...}
  </code></pre>
  
  <p>My validation code is:</p>
  
  <pre><code>ValidationAttribute[] attrs = bit of reflection here to populate from User class
  var ctx = new ValidationContext(name, null, null);
  var errors = new List&lt;ValidationResult&gt;();
  bool valid = Validator.TryValidateValue(name, ctx, errors, attrs);
  </code></pre>
  
  <p>It works fine until value of <code>name</code> is <code>null</code>. I'm getting <code>ArgumentNullException</code> when instantiating <code>ValidationContext</code> and don't understand why. <code>TryValidateValue()</code> also demands non-null context. I have a value and a list of attributes to validate against. What is that <code>ValidationContext</code> for?</p>