Home > database >  _userManager.ReplaceClaimAsync error Id = 414, Status = WaitingForActivation, Method = "{null}&
_userManager.ReplaceClaimAsync error Id = 414, Status = WaitingForActivation, Method = "{null}&

Time:02-27

In my controller asp.net core 6.0 I got this error when execute ReplaceClaimAsync:

Id = 414, Status = WaitingForActivation, Method = "{null}", Result = "{Not yet computed}"

var user11 = _userManager.FindByIdAsync(User.Id).Result;
user11.Email = user.Email;
var Result = _userManager.UpdateAsync(user11).Result;
if (!Result.Succeeded)
{
    ModelState.AddModelError(Result.Errors.First().Code, Result.Errors.First().Description);
    //throw new Exception(result.Errors.First().Description);
    return BadRequest(ModelState);
}
var claimsOriginaux = _userManager.GetClaimsAsync(user11);
var claimOld = claimsOriginaux.Result.FirstOrDefault(r => r.Type == JwtClaimTypes.GivenName);
var claimNew = new Claim(JwtClaimTypes.GivenName, User.GivenName);
if (claimNew.Value != claimOld.Value)
{
    var temp = _userManager.ReplaceClaimAsync(user11, claimOld, claimNew);
}
return NoContent(); //success

Any clue?

CodePudding user response:

You are calling a bunch of async methods, and you are not using them the way you should. You should await all async methods, instead of calling the .Result property.

CodePudding user response:

Using await

var user11 = await _userManager.FindByIdAsync(User.Id);
user11.Email = user.Email;
var Result = await _userManager.UpdateAsync(user11);
if (!Result.Succeeded)
{
    ModelState.AddModelError(Result.Errors.First().Code, Result.Errors.First().Description);
    //throw new Exception(result.Errors.First().Description);
    return BadRequest(ModelState);
}
var claimsOriginaux = await _userManager.GetClaimsAsync(user11);
var claimOld = claimsOriginaux.Result.FirstOrDefault(r => r.Type == JwtClaimTypes.GivenName);
var claimNew = new Claim(JwtClaimTypes.GivenName, User.GivenName);
if (claimNew.Value != claimOld.Value)
{
    var temp = await _userManager.ReplaceClaimAsync(user11, claimOld, claimNew);
}
return NoContent(); //success

or

Using GetAwaiter()

var user11 = _userManager.FindByIdAsync(User.Id).GetAwaiter().GetResult();
user11.Email = user.Email;
var Result = _userManager.UpdateAsync(user11).GetAwaiter().GetResult();
if (!Result.Succeeded)
{
    ModelState.AddModelError(Result.Errors.First().Code, Result.Errors.First().Description);
    //throw new Exception(result.Errors.First().Description);
    return BadRequest(ModelState);
}
var claimsOriginaux = _userManager.GetClaimsAsync(user11).GetAwaiter().GetResult();
var claimOld = claimsOriginaux.Result.FirstOrDefault(r => r.Type == JwtClaimTypes.GivenName);
var claimNew = new Claim(JwtClaimTypes.GivenName, User.GivenName);
if (claimNew.Value != claimOld.Value)
{
    var temp = _userManager.ReplaceClaimAsync(user11, claimOld, claimNew).GetAwaiter().GetResult();
}
return NoContent(); //success
  • Related