Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Error when saving an edited user #1322


User avatar
0
giel83 created

Hi,

I'm using ABP 0.83 (I think) with asp net zero and I'm getting an error when I'm trying to edit a user. The error is thrown at the UserAppService.cs: await UserManager.SetRoles(user, input.AssignedRoleNames); It cannot save the roles and the following error occurs:

Value cannot be null.\r\nParameter name: source

Attached are the properties of the user, and the assignedRoleNames are also filled properly (at least that is what it looks like)

Any idea what's going wrong and how to solve this?

Thanks


9 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Can you also share stacktrace for this exception ?

  • User Avatar
    0
    giel83 created

    Hi,

    This is everything of the stacktrace I can get

    StackTrace = " at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source)\r\n at Abp.Authorization.Users.AbpUserManager3.<SetRoles>d__7e.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.Compiler...

    Thanks

  • User Avatar
    0
    ismcagdas created
    Support Team

    I think the problem is, Roles collection of user is null. Can you share your dto you used when updating user ?

  • User Avatar
    0
    giel83 created

    Hi,

    I can't get the dto because it's somewhere in the boilerplate dll's, I haven't touched those. So when this is executed: var user = await UserManager.FindByIdAsync(input.User.Id.Value); the roles in user are indeed empty, but I can't have a good look at the FindByIdAsync method.

    Thanks

  • User Avatar
    0
    ismcagdas created
    Support Team

    Can you share user update method of UserAppService including method name and method input ?

  • User Avatar
    0
    giel83 created

    Yes, here it is!

    [AbpAuthorize(AppPermissions.Pages_Administration_Users_Edit)] protected virtual async Task UpdateUserAsync(CreateOrUpdateUserInput input) { Debug.Assert(input.User.Id != null, "input.User.Id should be set.");

            var user = await UserManager.FindByIdAsync(input.User.Id.Value);
    
            //Update user properties
            input.User.MapTo(user); //Passwords is not mapped (see mapping configuration)
    
            if (!input.User.Password.IsNullOrEmpty())
            {
                CheckErrors(await UserManager.ChangePasswordAsync(user, input.User.Password));
            }
    
            CheckErrors(await UserManager.UpdateAsync(user));
            try {
                //Update roles
                CheckErrors(await UserManager.SetRoles(user, input.AssignedRoleNames));
    
                await UserManager.SetRoles(user, input.AssignedRoleNames);
                if (input.SendActivationEmail)
                {
                    user.SetNewEmailConfirmationCode();
                    await _userEmailer.SendEmailActivationLinkAsync(user, input.User.Password);
                }
            }catch(Exception ex)
            {
                throw ex.InnerException;
            }
        }
    

    Btw, the CheckErrors method for update roles is the first line that throws the error

  • User Avatar
    0
    ismcagdas created
    Support Team

    I couldn't reproduce your scenario. Roles collection is either an empty array or filled with items, it was never null in my tests.

    Can you share your project and database to simulate same scenario if it is possible.

    You can send it privately to our info email address.

  • User Avatar
    0
    ngocthua92 created

    Hi, I facing same the problem, is it resolved?

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Can you check that in your AppService, the Roles property of your input is null or an empty list ?