我有一些代码正在从机器上的本地组中查找组成员身份。对于每个成员,它会尝试加载有关用户的一些信息(例如,找到一个组并获取其每个成员的名称)。
编码:
using (DirectoryEntry machine = new DirectoryEntry("WinNT://" + Environment.MachineName + ", Computer"))
{
using (DirectoryEntry group = machine.Children.Find(groupName, "group"))
{
object members = group.Invoke("members", null);
foreach (object groupMember in (IEnumerable) members)
{
using (DirectoryEntry member = new DirectoryEntry(groupMember))
{
member.RefreshCache();
string name = member.Name;
// <code snipped>
}
}
}
}
该代码在大多数情况下都可以正常工作,但是对于某些组成员,它会在抛出方法FileNotFoundException
时抛出一个RefreshCache()
:
System.IO.FileNotFoundException:
The filename, directory name, or volume label syntax is incorrect.
(Exception from HRESULT: 0x8007007B)
at System.DirectoryServices.Interop.UnsafeNativeMethods.IAds.GetInfo()
at System.DirectoryServices.DirectoryEntry.RefreshCache()
at GroupLookup.GetLocalGroupMembership(String groupName)
是什么导致FileNotFoundException
(以及它正在寻找什么文件)?