- 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):
- Roles and permissions (using the IdentityRoleManager + IPermissionManager)
- OrganizationUnits: (using the OrganizationUnitManager, all OU's seeded in seperate units of work)
Customers
|
-- Customer A
- 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,
1 Answer(s)
-
0
hi
Try to load the navicate properties of the user.
await UserRepository.FindByNormalizedUserNameAsync(IdentityServerConsts.GetCustomerUserName(), includeDetails: true, cancellationToken: cancellationToken);