使用 LDAP 过滤器查找所有结果。获取错误消息
DirectoryEntry testAD = new DirectoryEntry();
DirectorySearcher search = new DirectorySearcher(testAD);
StringBuilder add = new StringBuilder();
search.PropertiesToLoad.Add("mail");
search.Filter = "(&(objectClass=user))";
foreach (SearchResult SearchAll in search.FindAll())
{
DirectoryEntry de = SearchAll.GetDirectoryEntry();
add.Append(de.Properties["mail"].Value.ToString()); // error message here
}
PrefixDescription.Text = add.ToString();
我尝试首先查找所有电子邮件作为测试,然后查找所有信息(名字、姓氏等)并使用 LPAR 过滤器将其列出在文本框中,但在运行应用程序时不断收到此错误消息:
未将对象引用设置为对象的实例。
DirectoryEntry testAD = new DirectoryEntry();
DirectorySearcher search = new DirectorySearcher(testAD);
StringBuilder add = new StringBuilder();
search.PropertiesToLoad.Add("mail");
search.Filter = "(&(objectClass=user))";
foreach (SearchResult SearchAll in search.FindAll())
{
DirectoryEntry de = SearchAll.GetDirectoryEntry();
add.Append(de.Properties["mail"].Value.ToString()); // error message here
}
PrefixDescription.Text = add.ToString();
I'm trying to find all emails first as a test and then all information (first name, last name, etc) and list it in a text box using a LPAR filter but I keep getting this error message when I run the app:
Object reference not set to an instance of an object.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,您正在枚举用户 - 但您不能保证最终的用户将拥有电子邮件地址!您需要基本的“编程 101”错误预防:
通过此额外检查,您可以避免
Object reference not set....
错误...Well, you're enumerating users - but you have no guarantee that the resulting user will have an e-mail address! You need basic "programming 101" error prevention:
With this extra check, you avoid the
Object reference not set....
error...