Open Closed

Exception when adding a user to an organizationUnit. #2495


User avatar
0
marco@iwell.nl created
  • ABP Framework version: v4.3.0
  • UI type: Angular
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): tiered solution
  • Exception message and stack trace:
Exception has occurred: CLR/System.ArgumentNullException
Exception thrown: 'System.ArgumentNullException' in System.Linq.dll: 'Value cannot be null.'
   at System.Linq.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)
   at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)
   at Volo.Abp.Identity.IdentityUser.IsInOrganizationUnit(Guid organizationUnitId)
   at Volo.Abp.Identity.IdentityUser.AddOrganizationUnit(Guid organizationUnitId)
   at Iwell.Cloud.Portal.IdentityServer.UserDataSeedContributor.<SeedAsync>d__8.MoveNext() in /app/aspnet-core/src/Iwell.Cloud.Portal.Domain/IdentityServer/UserDataSeedContributor.cs:line 67
  • Steps to reproduce the issue:

When we seed a fresh (development) database we do a few things in a specific order (order managed by a single DataSeedContributor):

  1. Roles and permissions (using the IdentityRoleManager + IPermissionManager)
  2. OrganizationUnits: (using the OrganizationUnitManager, all OU's seeded in seperate units of work)
Customers
 |
 -- Customer A
  1. Users + add users to OU's + add users to roles

The problem occures in the userseeder when trying to add a user to an existing OU: (all checks and other code left out for readability)

var customerAOU = await _organizationUnitRepository.FirstOrDefaultAsync(ou => ou.DisplayName == IdentityServerConsts.GetCustomerAOUDisplayName());            
var customer = await _identityUserManager.FindByNameAsync(IdentityServerConsts.GetCustomerUserName());
customer.AddOrganizationUnit(customerAOU.Id);

The ArgumentNullException happens on the customer.AddOrganizationUnit(..) call.

As you can see in the attached picture the 'customerAOU' is an existing OrganizationUnit object and the 'customer' is an existing IdentityUser object.

The exact same thing happens when trying to add a role to a user using this code:

var adminRole = await _identityRoleManager.FindByNameAsync("admin");
customer.AddRole(adminRole.Id); 

I wonder if this is the way to add users to OU's (+ roles to users) or am I missing something here? Is there by any chance some more (technical or reference) documentation available on this topic?

If you need more information, or pieces of code, just let me know.

Any help would be appreciated!

Best regards,

Marco


1 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Try to load the navicate properties of the user.

     await UserRepository.FindByNormalizedUserNameAsync(IdentityServerConsts.GetCustomerUserName(), includeDetails: true, cancellationToken: cancellationToken);
    
Made with ❤️ on ABP v8.2.0-preview Updated on March 25, 2024, 15:11