我正在尝试枚举 SearchResultCollection 中的值。
一切编译正常,但我在这一行得到 0x8000500c 错误:
foreach (PropertyValueCollection e in de.Properties.Values)
{
sw.WriteLine(e.Value);
}
完整方法如下:
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();
}
你能帮我弄清楚为什么这不起作用吗?
谢谢