Directory Programming .NET

Active Directory and ADAM programming support for .NET developers
Welcome to Directory Programming .NET Sign in | Join | Help
in Search

S.DS.AM Errors "While trying to resolve a cross store reference"

Last post 09-13-2010, 8:31 AM by eamonnjennings. 1 replies.
Sort Posts: Previous Next
  •  09-09-2010, 10:14 AM 8540

    S.DS.AM Errors "While trying to resolve a cross store reference"

    Hi guys, I've written a small app which gets the groups from AD fom a db . Using these groups I want to find out the members of the groups and then submit that to the database. The code I have written works well in some customer sites but falls over badly in others, funny thing being one of the sites has 4000+ groups and about 400000 group members so I pretty confident of the scalability of the code. However when the code falls over it does so with a number of error messages:

    System.DirectoryServices.AccountManagement.PrincipalOperationException: While trying to resolve a cross-store reference, the SID of the target principal could not be resolved. The error code is 1332.

    at System.DirectoryServices.AccountManagement.ADStoreCtx.ResolveCrossStoreRefToPrincipal(Object o)

    at System.DirectoryServices.AccountManagement.ADUtils.DirectoryEntryAsPrincipal(DirectoryEntry de, ADStoreCtx storeCtx)

    at System.DirectoryServices.AccountManagement.ADDNLinkedAttrSet.get_CurrentAsPrincipal()

    at System.DirectoryServices.AccountManagement.PrincipalCollectionEnumerator.MoveNext()

    and

    System.DirectoryServices.AccountManagement.PrincipalOperationException: While trying to resolve a cross-store reference, the target principal could not be found in the domain indicated by the principal's SID.

    at System.DirectoryServices.AccountManagement.ADStoreCtx.ResolveCrossStoreRefToPrincipal(Object o)

    at System.DirectoryServices.AccountManagement.ADUtils.DirectoryEntryAsPrincipal(DirectoryEntry de, ADStoreCtx storeCtx)

    at System.DirectoryServices.AccountManagement.ADDNLinkedAttrSet.get_CurrentAsPrincipal()

    at System.DirectoryServices.AccountManagement.PrincipalCollectionEnumerator.MoveNext().

    After a number of these errors, say about 40 or so, the application dies totally. Seems to run out of memory, although I not 100% sure about that. From discussions with MS these are due to FSP in the group, and we have pretty much confirmed that with the customer. The code I have is as follows:

    foreach (Entity.tblADUser ad in adGroups)

    {

    //remove builtin and users container groups for speed.

    if (!ad.ADLDAP.Contains("CN=Builtin") && !ad.ADLDAP.Contains("CN=Users"))

    {

    var currGrp = GroupPrincipal.FindByIdentity(ctx, IdentityType.SamAccountName, ad.ADSAMAccountName);

    if (currGrp != null)

    {

    try

    {

    //create an enumerator to catch the groups.

    System.Collections.IEnumerator groupEnum = currGrp.Members.GetEnumerator();

    //only take out the users instead of all of the principals

    //foreach (var up in currGrp.Members)

    while (groupEnum.MoveNext())

    {

    try

    {

    var vup = groupEnum.Current;

    if (vup.GetType().ToString() == "System.DirectoryServices.AccountManagement.UserPrincipal")

    {

    UserPrincipal up = (UserPrincipal)vup;

    if (up.SamAccountName != "" || up.SamAccountName != null)

    {

    //add this user to the class of users.

    ADGroupUsers adgu = new ADGroupUsers();

    adgu.ADGUID = 0;

    adgu.ADGUDelete = 0;

    adgu.ADGUGroupADID = 0;

    adgu.ADGUGroupSAMAccountName = ad.ADSAMAccountName;

    adgu.ADGUUserADID = 0;

    adgu.ADGUUserSAMAccountName = up.SamAccountName;

    adGroupList.Add(adgu);

    }

    up.Dispose();

    }

    }

    catch (Exception ex)

    {

    }

    }

    }

    catch (Exception ex)

    {

    string sEvent;

    if (ex.InnerException != null)

    sEvent = "Group Users Full Group Joiners Error Event - " + ex.Message + " , Inner Exception: " + ex.InnerException.ToString() + " , Source: " + ex.Source + ", Extras: " + ex.GetBaseException();

    else

    sEvent = "Group Users Full Group Joiners Error Event - " + ex.Message + " , Source: " + ex.Source + ", Extras: " + ex.GetBaseException();

    Error newError = new Error();

    newError.WriteLog(sEvent);

    }

    currGrp.Dispose();

    }

    }

    }

    The problem seems to stem from the FindByIdentity method, I've found a few references in places talking of errors with this, but nothing concrete. I've a case with MS Developer support at the moment but was wondering if anyone had seen this behaviour before.

    Thanks
    Eamonn

  •  09-13-2010, 8:31 AM 8544 in reply to 8540

    Re: S.DS.AM Errors "While trying to resolve a cross store reference"

    Replying in case anyone comes across this again. There are two issues here from chatting to MS support engineers. One is that there is a memory leak in FindByIdentity, see here : http://msdn.microsoft.com/en-us/library/bb345628(v=VS.90).aspx

    Also, if we find a group using the FindBy Identity method and the group has a FSP it will fail with the errors above.

    Best way is to use DirectoryEntry objects, which is a bit weird, having to go to .NET 1.1 stuff. Maybe this will be fixed in .NET 4.0, will have to check.

    E

View as RSS news feed in XML