While fetching users from group, giving exception message as "While trying to resolve a cross-store reference, the SID of the target principal could not be resolved. The 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;
When doing
foreach (UserPrincipal user in users)
I am getting the error. Any suggestions i can check for this error or skip this member from list during looping.