Unknown Errors Unknown error (0x8000500c) help in DirectoryService

Last post 07-28-2007 5:12 AM by manach. 1 replies.

Sort Posts:

  • Unknown Errors Unknown error (0x8000500c) help in DirectoryService

    07-24-2007, 3:49 AM
    • Loading...
    • gakuci
    • Joined on 05-10-2007, 2:26 AM
    • Posts 7

     Hi all,

    I'm new to active directory programming. I am trying to write a console
    program that read the LDAP attributes and generate a csv file.
    I've specified the required attributes in a string array. It works properly
    for most attributes but get strange error for some attributes such attributes as uidNumber, gidNumber.

    The error message is like the following.

    System.Runtime.InteropServices.COMException was unhandled
    Message="Unknown error (0x8000500c)"
    Source="CSVFileExporter"
    ErrorCode=-2147463156
    StackTrace:
       at System.DirectoryServices.PropertyValueCollection.PopulateList()
       at System.DirectoryServices.PropertyValueCollection..ctor(DirectoryEntry entry, String propertyName)
       at System.DirectoryServices.PropertyCollection.get_Item(String propertyName)

    Does any body know the solutions? Please help me.


    The following is my codeing use to retrieve LDAP attribue and create csv file.    

    try
    {
        DirectoryEntry entry = new DirectoryEntry();
        entry.Path = LDAPServerPath;
        entry.Username = user;
        entry.Password = password;
        entry.AuthenticationType = AuthenticationTypes.None;

        DirectorySearcher mySearcher = new DirectorySearcher(entry);
        mySearcher.Filter = filter;

        TextWriter tw = new StreamWriter("D:\\myCSV.csv", true);

        mySearcher.CacheResults = false;
        StringBuilder str = new StringBuilder();

        //Add all properties that need to be fetched
        for(int i = 0; i < expectedProperties.Length; i++)
        mySearcher.PropertiesToLoad.Add(expectedProperties[i]);

        mySearcher.SearchScope = SearchScope.Subtree;
        SearchResultCollection resultUsers = mySearcher.FindAll();

        foreach (SearchResult srUser in resultUsers)
        {
            try
            {
                DirectoryEntry de = srUser.GetDirectoryEntry();
                for(int c = 0; c < expectedProperties.Length; c++)
                {
                    if (de.Properties.Contains(expectedProperties[c]))
                    {
                        str.Append(de.Properties[expectedProperties[c]].Value.ToString());
                    }
                    else
                    {
                        str.Append("");
                    }
                    if(c != expectedProperties.Length - 1)
                    str.Append(seperator);
                 }
                  de.Close();

                tw.WriteLine(str);
                str.Remove(0, str.Length);
            }
            catch(Exception ee)
           {
                throw ee;
            }
        }
        tw.Close();
    }
    catch (COMException ex)
    {
        throw ex;
    }
    catch (Exception e)
    {
        throw e;
    }

    Regards,
    gakuci

  • Re: Unknown Errors Unknown error (0x8000500c) help in DirectoryService

    07-28-2007, 5:12 AM
    • Loading...
    • manach
    • Joined on 05-11-2005, 1:03 PM
    • Ho Chi Minh City, Vietnam
    • Posts 12

    Hi gakuci,

    For some entry, we cannot retrieve all its property. So, we should verify its information is not null before using it.
     

    if(de.Properties[expectedProperties[c]].Value != null)
    {
    	str.Append(de.Properties[expectedProperties[c]].Value.ToString());        
    } 
    Thanks,
    Manach. 
     
Page 1 of 1 (2 items)
Microsoft Communities
Page view counter