C
C#2d ago
its0mar

Optimistic concurrency failure, object has been modified

public async Task<IActionResult> UpdateInfo(UpdateInfoDTO dto)
{
if (!ModelState.IsValid)
{
ViewBag.Errors = ModelState.Values.SelectMany(e => e.Errors).Select(e => e.ErrorMessage).ToList();
return View(dto);
}

ApplicationUser user = new ApplicationUser { UserName = dto.UserName, PersonName = dto.PersonName, Email = dto.Email, PhoneNumber = dto.Phone, ProfilePicPath = dto.ProfilePicture };
user.SecurityStamp = Guid.NewGuid().ToString();
var result = await _userManager.UpdateAsync(user);

if (result.Succeeded)
{
return RedirectToAction(nameof(HomeController.Index), "Home");
}
else
{
foreach (IdentityError error in result.Errors)
{
ModelState.AddModelError("UpdateInfo", error.Description);
}
return View(dto);
}

}
public async Task<IActionResult> UpdateInfo(UpdateInfoDTO dto)
{
if (!ModelState.IsValid)
{
ViewBag.Errors = ModelState.Values.SelectMany(e => e.Errors).Select(e => e.ErrorMessage).ToList();
return View(dto);
}

ApplicationUser user = new ApplicationUser { UserName = dto.UserName, PersonName = dto.PersonName, Email = dto.Email, PhoneNumber = dto.Phone, ProfilePicPath = dto.ProfilePicture };
user.SecurityStamp = Guid.NewGuid().ToString();
var result = await _userManager.UpdateAsync(user);

if (result.Succeeded)
{
return RedirectToAction(nameof(HomeController.Index), "Home");
}
else
{
foreach (IdentityError error in result.Errors)
{
ModelState.AddModelError("UpdateInfo", error.Description);
}
return View(dto);
}

}
hello, when I try to update a user I get Optimistic concurrency failure, object has been modified , how I can fix it and what is the reason of it
7 Replies
Mąż Zuzanny Harmider Szczęście
show the exact error message
its0mar
its0marOP2d ago
Optimistic concurrency failure, object has been modified
Mąż Zuzanny Harmider Szczęście
show console output
its0mar
its0marOP2d ago
No description
its0mar
its0marOP2d ago
No description
glhays
glhays2d ago
Maybe you can find something here on what can fix or help. Maybe you already saw this. https://stackoverflow.com/questions/52553964/how-to-deal-with-concurrency-failure-on-identityuser-update
Stack Overflow
How to deal with concurrency failure on IdentityUser update?
I have a method to update user claims within our app. I am logged as an admin user who can edit other users. I am trying to remove existing claims of one user and assign new ones. When removing ...
its0mar
its0marOP17h ago
the problem I didn`t actually get the user by FindByIdAsync or something else

Did you find this page helpful?