利用可能なドメインのリストを照会するために LDAP を使用しています。1 つの NIC カードが利用可能で、ドメインのリストを正常にクエリしているマシンでこれを実行すると、私のロジックは正常に動作します。ドメイン B、例外の理由は単純です。つまり、DirectoryEntry() バインディングが失敗しています。
このためにのみ LDAP プロバイダーを使用する必要があります。
以下はコード スニペットです。
using (DirectoryEntry RootDSE = new DirectoryEntry("LDAP://rootDSE"))
{
// Retrieve the Configuration Naming Context from RootDSE
string configNC = RootDSE.Properties["configurationNamingContext"].Value.ToString();
// Connect to the Configuration Naming Context
using (DirectoryEntry configSearchRoot = new DirectoryEntry("LDAP://" + configNC))
{
// Search for all partitions where the NetBIOSName is set.
using (DirectorySearcher configSearch = new DirectorySearcher(configSearchRoot))
{
configSearch.Filter = ("(NETBIOSName=*)");
// Configure search to return dnsroot and ncname attributes
configSearch.PropertiesToLoad.Add("dnsroot");
configSearch.PropertiesToLoad.Add("ncname");
using (SearchResultCollection forestPartitionList = configSearch.FindAll())
{