When you try to resolve the cross-store link, the SID of the target member cannot be resolved. Error Code: 1332

By acquiring users from a group, providing an exception message as "When trying to resolve a cross-storage link, the SID of the target member cannot be resolved. Error code is 1332."

PrincipalContext ctx = null; if (!string.IsNullOrWhiteSpace(adUserName)) { ctx = new PrincipalContext(ContextType.Domain, domainName, adUserName, adPassword); } else { ctx = new PrincipalContext(ContextType.Domain, domainName); } var groupNames = commaSeparatedGroupNames.Split(','); IEnumerable<Principal> users = null; foreach (var groupName in groupNames) { if (!string.IsNullOrWhiteSpace(groupName)) { var userGroup = GroupPrincipal.FindByIdentity(ctx, groupName.Trim()); if (userGroup == null) throw new InvalidOperationException("Active Directory Group Not Found :: " + groupName); var usersInGroup = userGroup.GetMembers(); if (users == null) { users = usersInGroup; } else { users = users.Union(usersInGroup); } } } return users; 

By doing

 foreach (UserPrincipal user in users) 

I get an error message. Any suggestions I can check for this error or skip this item from the list during the loop.

0
source share
1 answer

I think your problem is with the return type of group.GetMembers() , which is not necessarily UserPrincipal , but a Principal .

So you can check if Principal is a UserPrincipal or GroupPrincipal .

 foreach(var principal in groupMembers) 

would be the best choice in your case.

0
source

Source: https://habr.com/ru/post/1441822/


All Articles