title: Override async method with exception handling on result
body: <p>On of the methods I'm having difficulty with is:</p>
  
  <pre><code>if (ModelState.IsValid)
  {
      var user = new User { UserName = model.Email, Email = model.Email };
      IdentityResult result = null;
      try
      {
          result = await this._userManager.CreateAsync(user, model.Password).Result;
      }
      catch (Exception ex)
      {
      }
  
      if (result != null &amp;&amp; result.Succeeded)
      {
        // not important code
      }
      AddErrors(result);
  }
  
  // If we got this far, something failed, redisplay form
  return View(model);
  </code></pre>
  
  <p>I believe there is a bug in the <code>CreateAsync(TUser user, string passwor)</code> method (Microsoft.AspNet.Identity, Microsoft.AspNet.IdentityCore.dll, v2.0.0.0).  If I configure the user manager with a password validator and the password doesn't validate, there is no exception (good path) and the <code>IdentityResult</code> looks like</p>
  
  <pre><code>Errors      {string[1]}
  - string[]  {string[1]}
  -- [0]      "Passwords must have at least...."
  </code></pre>
  
  <p>However, if pass in an existing user, instead of a nice IdentityResult, the method throws an <code>EntityValidationErrors</code> exception (bad path). I'd like to put the above code back to the original without a try catch and truly rely on the <code>IdentityResult</code>:</p>
  
  <pre><code>if (ModelState.IsValid)
  {
      var user = new User { UserName = model.Email, Email = model.Email };
  
      var result = this._userManager.CreateAsync(user, model.Password);
  
      if (result.Succeeded)
      {
        // not important code
      }
      AddErrors(result);
  }
  </code></pre>
  
  <p>And override the <code>CreateAsync()</code> method:</p>
  
  <pre><code>public override Task&lt;IdentityResult&gt; CreateAsync(User user, string password)
  {
      Task&lt;IdentityResult&gt; result = null;
      try
      {
          var ir = base.CreateAsync(user, password);
  
          return ??;
      }
      catch (DbEntityValidationException ex)
      {
          var errors = ex.EntityValidationErrors
              .Where(e =&gt; e.IsValid)
              .SelectMany(e =&gt; e.ValidationErrors)
              .Select(e =&gt; e.ErrorMessage)
              .ToArray();
          var ir = new IdentityResult(errors);
  
          return ??;
      }
  
      return result;
  }
  </code></pre>
  
  <p>However, I simply don't know how to return a task nor if this is the right direction in terms of fixing the problem.</p>
  
  <p>I suppose I could this the following but using another thread that will just return a value, seems absolutely the wrong route.</p>
  
  <pre><code>result = Task.Factory.StartNew(() =&gt;
  {
    return ir;
  });
  </code></pre>