C# とディレクトリ サービスを使用して簡単なデータ取得を試みていますが、何らかの理由でどの XP マシンでも機能しません。私のコードを Server 2003 マシンで実行しても問題はありません。XPで必要な再配布可能ファイルがあるかどうか、または機能が単にそこにないかどうかを調べるのにかなりの時間を費やしましたが、XPで動作する同様のコードを持つ他の開発者への参照を見つけました. 誰かが共有する経験やアドバイスを持っているなら、私はそれを感謝します.
私のためにクラッシュしている簡単なコードスニペット:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.DirectoryServices;
namespace IIS_Site_Query_Tool
{
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
DirectoryEntry W3SVC = new DirectoryEntry("IIS://localhost/w3svc");
foreach (DirectoryEntry Site in W3SVC.Children)
{
//Do some data processing
}
}
}
}
これを XP で実行すると、HRESULT が -2147463168 の次のエラーが表示されます。
System.Runtime.InteropServices.COMException was unhandled
Message="Unknown error (0x80005000)"
Source="System.DirectoryServices"
ErrorCode=-2147463168
StackTrace:
at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
at System.DirectoryServices.DirectoryEntry.Bind()
at System.DirectoryServices.DirectoryEntry.get_IsContainer()
at System.DirectoryServices.DirectoryEntries.ChildEnumerator..ctor(DirectoryEntry container)
at System.DirectoryServices.DirectoryEntries.GetEnumerator()
...
エラーのさまざまな情報をグーグルで検索すると、これはかなり一般的な COM 相互運用エラーであると考えるようになり、現時点では考えがありません。どんな助けでも大歓迎です!