A 向 Active Directory 架构添加了自定义属性。在一台机器上,当我尝试查询属性时,我从代码中返回错误。
这是用于测试的 C# 版本。
static class Program
{
static void Main()
{
Console.ReadLine();
DirectoryEntry directoryEntry = (DirectoryEntry)UserPrincipal.Current.GetUnderlyingObject();
//Execption on this line
var allowedDatabases = directoryEntry.Properties["vwDBAccess"];
foreach (var record in allowedDatabases.OfType<String>())
{
Console.WriteLine(record);
}
Console.ReadLine();
}
}
System.Runtime.InteropServices.COMException 未处理 消息=未知错误 (0x8000500c) 源 = System.DirectoryServices 错误代码=-2147463156 堆栈跟踪: 在 System.DirectoryServices.PropertyValueCollection.PopulateList() 在 System.DirectoryServices.PropertyValueCollection..ctor(DirectoryEntry 条目,字符串 propertyName) 在 System.DirectoryServices.PropertyCollection.get_Item(字符串属性名称) 在 C:\Users\srchamberlain.VW\documents\visual studio 2010\Projects\Sandbox Console\Sandbox Console\Program.cs:line 16 中的 Sandbox_Console.Program.Main() 内部异常:
错误代码0x8000500c
代表E_ADS_CANT_CONVERT_DATATYPE
。这只发生在一台机器上。我有 3 台其他计算机(与第一台计算机位于同一域的所有部分),并且在为完全相同的用户运行完全相同的代码并给出属性内容时,它们的行为正确。此外,如果我以不同用户的身份在同一个盒子上运行,但查询坏用户的属性,我可以在以另一个用户身份连接时正确提取信息。
我尝试使用此知识库文章中的技术刷新盒子上的架构,但问题仍然存在。
这台电脑出了什么问题?
澄清:
vwDBAccess 是一个多值字符串,所以当它工作时directoryEntry.Properties["vwDBAccess"]
返回一个string
有一个项目,sting[]
当有多个项目时,以及null
没有项目时。此帐户设置了 3 个项目。当我以其他用户身份运行并查询坏用户时,我会正确string[3]
返回。