- ABP Framework version: 7.4.2
- UI Type: Angular
- Database System: EF Core (PostgreSQL.)
- Tiered (for MVC) or Auth Server Separated (for Angular): yes
- Exception message and full stack trace:
- Steps to reproduce the issue:
public async Task<bool> CreateAsync(IdentityUserCreateDto input, Guid tenantId)
{
try
{
var newUserName = await GetUniqueUserNameAsync(input.Name.Trim(), input.Surname.Trim());
var user = new IdentityUser(\_guidGenerator.Create(), newUserName.Trim(), input.Email, tenantId);
var creationResult = await \_identityUserManager.CreateAsync(user, input.Password.Trim());
creationResult.CheckErrors();
await \_identityUserManager.SetEmailAsync(user, input.Email.Trim());
await \_identityUserManager.SetPhoneNumberAsync(user, input.PhoneNumber.Trim());
user.Name = input.Name.Trim();
user.Surname = input.Surname.Trim();
var claimsToAdd = new List\<Claim>
{
new Claim(ClaimTypes.Email, input.Email.Trim()),
};
await \_identityUserManager.AddClaimsAsync(user, claimsToAdd);
await \_unitOfWorkManager.Current.SaveChangesAsync();
await assignRoles(input, user);
var userDetails = await \_identityUserManager.GetByIdAsync(user.Id);
if (userDetails != null)
{
userDetails.SetProperty("Status", 1);
userDetails.SetProperty("Language", "en");
}
await \_unitOfWorkManager.Current.SaveChangesAsync();
}
catch (Exception ex)
{
}
}
<br>
After successfully adding the user to the database, I encountered an error when executing the line var userDetails = await _identityUserManager.GetByIdAsync(user.Id);
.
I have verified that the user was added to the database and that the user ID is present and correct.
7 Answer(s)
-
0
Hi,
you can try to create a new uow to create a user.
for example:
Guid userId; using (var uow = _unitOfWorkManager.Begin(requiresNew: true, isTransactional: true)) { var newUserName = await GetUniqueUserNameAsync(input.Name.Trim(), input.Surname.Trim()); var user = new IdentityUser(_guidGenerator.Create(), newUserName.Trim(), input.Email, tenantId); var creationResult = await _identityUserManager.CreateAsync(user, input.Password.Trim()); creationResult.CheckErrors(); await _identityUserManager.SetEmailAsync(user, input.Email.Trim()); await _identityUserManager.SetPhoneNumberAsync(user, input.PhoneNumber.Trim()); user.Name = input.Name.Trim(); user.Surname = input.Surname.Trim(); ...... userId = user.Id; await uow.CompleteAsync(); } var userDetails = await _identityUserManager.GetByIdAsync(userId);
-
0
Hi,
you can try to create a new uow to create a user.
for example:
Guid userId; using (var uow = _unitOfWorkManager.Begin(requiresNew: true, isTransactional: true)) { var newUserName = await GetUniqueUserNameAsync(input.Name.Trim(), input.Surname.Trim()); var user = new IdentityUser(_guidGenerator.Create(), newUserName.Trim(), input.Email, tenantId); var creationResult = await _identityUserManager.CreateAsync(user, input.Password.Trim()); creationResult.CheckErrors(); await _identityUserManager.SetEmailAsync(user, input.Email.Trim()); await _identityUserManager.SetPhoneNumberAsync(user, input.PhoneNumber.Trim()); user.Name = input.Name.Trim(); user.Surname = input.Surname.Trim(); ...... userId = user.Id; await uow.CompleteAsync(); } var userDetails = await _identityUserManager.GetByIdAsync(userId);
I used above code, But still facing same issue. I've created a class file inside the shared folder and am calling this method from the app service. Since we have a requirement to make this method common, it should be accessible to everyone.
-
0
Could you share a minimal reproduceible project with me? i will check it.
shiwei.liang@volosoft.com
-
0
My project is very large, and due to policy restrictions, it's not feasible to share the code. Can you suggest an alternative solution?
-
0
Hi,
you can use a new project to reproduce the problem.
-
0
ok let me try
-
0
okay