title: .NET Core 2 Identity CreateAsync Error Catching
body: <p>I am getting an error when trying to CreateAsync a user.</p>
  
  <pre><code>var create = await _userManager.CreateAsync(user, model.Password);
  </code></pre>
  
  <p>There is a property I can access on the <code>IdentityResult</code> called <code>errors</code>. However I can't work out how to access it. Any idea how I can catch it so I can see what it is erroring on?</p>
  
  <p>I've posted the full controller code below. For some reason whenever I try and do anything with my var create it just ignores it. I can't even step into it.</p>
  
  <pre><code>namespace TechsportiseOnline.Controllers
  {
      [Produces("application/json")]
      [Route("api/[controller]/[action]")]
      public class RegistrationController : Controller
      {
          private readonly UserManager&lt;ApplicationUser&gt; _userManager;
          private readonly SignInManager&lt;ApplicationUser&gt; _signInManager;
          private readonly IConfiguration _configuration;
          private readonly IOptions&lt;JWTSettings&gt; _jwtConfig;
          private readonly IEmailSender _emailSender;
  
          public RegistrationController(
                UserManager&lt;ApplicationUser&gt; userManager,
                SignInManager&lt;ApplicationUser&gt; signInManager,
                IConfiguration configuration,
                IOptions&lt;JWTSettings&gt; jwtConfig,
                IEmailSender emailSender)
                      {
                          _userManager = userManager;
                          _signInManager = signInManager;
                          _configuration = configuration;
                          _jwtConfig = jwtConfig;
                          _emailSender = emailSender;
  
          }
  
          [AllowAnonymous]
          [HttpPost]
          public async Task&lt;IActionResult&gt; Register([FromBody] RegisterModel model)
          {
              if (ModelState.IsValid)
              {
  
                  var user = new ApplicationUser
                  {
                      UserName = model.Email,
                      Email = model.Email,
                      FirstName = model.FirstName,
                      LastName = model.LastName,
                      MobileNumber = model.MobileNumber,
                      Marketing = model.Marketing,
                      Newsletter = model.Newsletter
                  };
  
                  var result = new CreateUserResult();
  
                  var    create = await _userManager.CreateAsync(user, model.Password);
  
  
  
  
                  if (create.Succeeded == true)
                  {
  
                      var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
                      var callbackUrl = Url.EmailConfirmationLink(user.Id, code.ToString(), Request.Scheme);
                      await _emailSender.SendEmailConfirmationAsync(model.Email, callbackUrl);
  
  
                      //await _createContact.CreateContactAsync(model.Email, model.FirstName, model.LastName, model.Marketing, model.Newsletter);
                      var fields = new Dictionary&lt;string, string&gt;();
                      fields.Add("firstname", model.FirstName);
                      fields.Add("lastname", model.LastName);
                      fields.Add("newsletter", model.Newsletter.ToString());
                      fields.Add("marketing", model.Marketing.ToString());
                      string publicaccountid = "55ebcc8b-b23f-4843-9dcb-1df08811de65";
                      var createcontact = ElasticEmailClient.Api.Contact.AddAsync(publicAccountID: publicaccountid, email: model.Email, field: fields);
  
  
  
                      //await _signInManager.SignInAsync(user, isPersistent: false);
                      return CreatedAtRoute("CreateAccount", model);
                  }
                  else
                  {
                      return BadRequest("Could not register account");
                  }
              }
              else
              {
                  return BadRequest("The model is invalid");
              }
          }       
      }
  
  
  }
  </code></pre>