更新时间:2022-04-11 07:56:05
不是100%不确定这是否是问题-但是 PrincipalSearcher
确实返回了 Principal
对象。
Not 100% sure if that's the problem - but PrincipalSearcher
really returns a list of Principal
objects.
因此,如果-由于某种原因-搜索者返回的内容不是 UserPrincipal
,那么您的对象结果
将为空-不是 .DisplayName
属性。
So if - for whatever reason - your searcher would return something that's not a UserPrincipal
, then your object result
would be null - not it's .DisplayName
property.
因此,您应该将支票更改为:
So you should change your checking to:
foreach (UserPrincipal result in search.FindAll())
{
if (result != null && result.DisplayName != null)
{
comboBox2.Items.Add(result.DisplayName);
}
}