API Reference
LdapSafe
Provides safe enumeration helpers for DirectorySearcher and DirectoryEntry.Children that never throw out of the iterator; errors are logged and enumeration stops.
Inheritance
- Object
- LdapSafe
Methods
EnsurePinnedToHealthyDc(System.DirectoryServices.DirectorySearcher arg1) #Proactively pins the provided DirectorySearcher to a healthy DC before executing a query. This avoids the provider selecting an unhealthy server implicitly when SearchRoot is serverless or points at a previously failed host. Uses quick RootDSE + subtree probes with short timeouts; logs bans/skips/failovers via LdapDiagnostics.
Parameters
- arg1 System.DirectoryServices.DirectorySearcher
public static IEnumerable<SearchResult> Enumerate(DirectorySearcher searcher, String context = null) #IEnumerable<SearchResult>Enumerates SearchResult items from the provided searcher. Exceptions are caught and logged; the iterator stops on failure instead of throwing.
Parameters
- searcher System.DirectoryServices.DirectorySearcher
- The directory searcher instance.
- context System.String = null
- Optional context string for logging.
Returns
Safe enumerable of results, possibly empty when errors occur.
public static IEnumerable<DirectoryEntry> EnumerateChildren(DirectoryEntry parent, String context = null) #IEnumerable<DirectoryEntry>Enumerates child DirectoryEntry objects for the given parent, logging errors and stopping the iterator on failures.
Parameters
- parent System.DirectoryServices.DirectoryEntry
- The parent directory entry.
- context System.String = null
- Optional context string for logging.
Returns
Safe enumerable of child entries, possibly empty when errors occur.
public static IEnumerable<SearchResult> EnumerateSuppressNotFound(DirectorySearcher searcher, String context = null) #IEnumerable<SearchResult>Enumerates SearchResult items, suppressing LDAP "no such object" errors (0x80072030) which are expected when optional naming contexts are missing.
Parameters
- searcher System.DirectoryServices.DirectorySearcher
- The directory searcher instance.
- context System.String = null
- Optional context string for logging.
Returns
Safe enumerable of results, possibly empty when errors occur.
TryRebindAlternate(System.DirectoryServices.DirectorySearcher arg1, System.DirectoryServices.DirectorySearcher@ arg2) #Attempts to rebind a failed DirectorySearcher to an alternate healthy DC. Strategy: 1) Extract domain and base DN from the failed search root path. 2) Ban the failed host briefly to avoid immediate reselection. 3) Iterate preferred DCs ordered by recent health; quick RootDSE probe using ~90% of attempt budget, then validate subtree responsiveness at the intended base DN. 4) On success, build a new DirectorySearcher with identical parameters rooted at the chosen DC.
Parameters
- arg1 System.DirectoryServices.DirectorySearcher
- arg2 System.DirectoryServices.DirectorySearcher@
Inherited Methods
Properties
public static TimeSpan DefaultBanDuration { get; set; } #Default ban duration used when marking a DC unhealthy due to timeouts/connectivity errors. Configurable to tune aggressiveness of failover behavior.
Fields
RootDseProbeFraction #Fraction of the per-attempt budget used for the quick RootDSE probe before validating subtree responsiveness on a candidate DC.