I am using DirectorySearcher
to look up user accounts based on email addresses:
using (var searcher = new DirectorySearcher
{
SearchRoot = new DirectoryEntry($"LDAP://DC={companyOfficeLocation},DC={companyDomain},DC=com"),
SearchScope = SearchScope.Subtree,
Filter = $"(mail={email})",
PropertiesToLoad = { "sAMAccountName" },
ReferralChasing = ReferralChasingOption.All,
})
{
return searcher.FindAll().Cast<SearchResult>()
.Select(r => (string)r.Properties["sAMAccountName"][0])
.ToList();
}
This code intermittantly fails with System.DirectoryServices.DirectoryServicesCOMException
with the error message A referral was returned from the server.
.
These errors are not consistent across machines (e. g. on different web servers the same query might fail or succeed in the same timeframe). There is some indication that ActiveDirectory server reboots or web server reboots may trigger the errors.
I'm wondering: what are the possible causes of referral errors? Why am I seeing referral errors despite setting the ReferralChasing
property to All
?
EDIT:
A bit more information captured from the ExtendedErrorMessage
property of the DirectoryServicesCOMException
:
0000202B: RefErr: DSID-031007F3, data 0, 1 access points ref 1: 'arlington.predictivetechnologies.com'