title: TryValidateModel in asp.net core throws Null Reference Exception while performing unit test
body: <p>I'm trying to write unit tests for ModelState validation for an Asp.Net Core Web API.</p>
  
  <p>I read that, the best way to do so is to use <code>TryValidateModel</code> function. But, every time I run the unit test, it throws NullReference exception.<br>
  I found many articles suggesting <code>controller.ModelState.AddModelError("","")</code>, but I'm not interested in this, as I believe that it beats the actual purpose of the real model validation.</p>
  
  <pre class="lang-cs prettyprint-override"><code>[TestMethod]
  public void TestMethod1()
  {
      var controller = new TestController();
  
      controller.Post(new Model());
  }
  
  
  public class TestController : Controller
  {
      public IActionResult Post(Model model)
      {
          bool b = TryValidateModel(model)
  
          return Ok();
      }
  }
  </code></pre>
  
  <p><code>TryValidateModel(model)</code> always throws NullReference Exception from <code>TryValidateModel(model, prefix)</code> function.</p>
  
  <p>Appreciate any help.</p>