Why am I getting a 0x8000500c error when enumerating a SearchResultCollection in .Net

孤者浪人 提交于 2019-12-11 11:07:57

问题


I am trying to enumerate the values in a SearchResultCollection.

Everything compiles fine, but I get the 0x8000500c error on this line:

foreach (PropertyValueCollection e in de.Properties.Values)
{
    sw.WriteLine(e.Value);
}

Full method is below:

private static void GetValues()
{
    var directoryEntry = new DirectoryEntry("LDAP://8.8.8.8:8888", "foo", "bar",
                                                       AuthenticationTypes.None);
    var ds = new DirectorySearcher(directoryEntry);
    var final = ds.FindAll();

    var sw = new StreamWriter(@"C:\z\FooBar.txt");

    var titlesDone = false;

    foreach (var de in from SearchResult x in final select x.GetDirectoryEntry())
    {
        if (!titlesDone)
        {
            foreach (string d in de.Properties.PropertyNames)
            {
                sw.WriteLine(d);
                titlesDone = true;
            }
        }


        foreach (PropertyValueCollection e in de.Properties.Values)
        {
            //I get the error on the below line
            sw.WriteLine(e.Value);
        }
    }

    sw.Flush();
    sw.Close();
}

Can you help me figure out why this isn't working?

Thanks


回答1:


Active Directory error codes are listed in the AdsErr.h SDK header file:

//
// MessageId: E_ADS_CANT_CONVERT_DATATYPE
//
// MessageText:
//
//  The directory datatype cannot be converted to/from a native DS datatype
//
#define E_ADS_CANT_CONVERT_DATATYPE      _HRESULT_TYPEDEF_(0x8000500CL)

So the problem is on the other end of the wire, there's some kind of unusual custom property in the directory entry that it doesn't know how to convert to a common data type. Talk to the server admin to get this resolved or be more selective with the properties you need to read.



来源:https://stackoverflow.com/questions/10673555/why-am-i-getting-a-0x8000500c-error-when-enumerating-a-searchresultcollection-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!