遍历属性时 ActiveDirectory 错误 0x8000500c
- 作者: 外貌協會理事長
- 来源: 51数据库
- 2022-10-21
问题描述
我得到了以下代码段(SomeName/SomeDomain 在我的代码中包含真实值)
I got the following snippet (SomeName/SomeDomain contains real values in my code)
var entry = new DirectoryEntry("LDAP://CN=SomeName,OU=All Groups,dc=SomeDomain,dc=com");
foreach (object property in entry.Properties)
{
Console.WriteLine(property);
}
前 21 个属性打印正常,但随后失败:
It prints OK for the first 21 properties, but then fail with:
COMException {"Unknown error (0x8000500c)"}
at System.DirectoryServices.PropertyValueCollection.PopulateList()
at System.DirectoryServices.PropertyValueCollection..ctor(DirectoryEntry entry, String propertyName)
at System.DirectoryServices.PropertyCollection.PropertyEnumerator.get_Entry()
at System.DirectoryServices.PropertyCollection.PropertyEnumerator.get_Current()
at ActiveDirectory.Tests.IntegrationTests.ObjectFactoryTests.TestMethod1() in MyTests.cs:line 22
为什么?我该如何预防?
Why? How can I prevent it?
更新
这是一个失败的自定义属性.
It's a custom attribute that fails.
在枚举属性之前,我尝试使用 entry.RefreshCache() 和 entry.RefreshCache(new[]{"theAttributeName"})t帮助).
I've tried to use entry.RefreshCache() and entry.RefreshCache(new[]{"theAttributeName"}) before enumerating the properties (which didn't help).
更新 2
entry.InvokeGet("theAttributeName") 有效(并且没有 RefreshCache).
entry.InvokeGet("theAttributeName") works (and without RefreshCache).
有人能解释一下原因吗?
Can someone explain why?
更新 3
如果我为项目提供 FQDN 就可以了:LDAP://srv00014.ssab.com/CN=SomeName,xxxx
It works if I supply the FQDN to the item: LDAP://srv00014.ssab.com/CN=SomeName,xxxx
赏金
我正在寻找解决以下问题的答案:
I'm looking for an answer which addresses the following:
- 为什么 entry.Properties["customAttributeName"] 因上述异常而失败
- 为什么 entry.InvokeGet("customAttributeName") 有效
- 异常的原因
- 如何让两者都工作
- Why entry.Properties["customAttributeName"] fails with the mentioned exception
- Why entry.InvokeGet("customAttributeName") works
- The cause of the exception
- How to get both working
推荐答案
如果想要从一台非自定义属性所在域的一部分(凭据登录用户的无关紧要)需要完全通过对象的限定名称正在尝试访问,否则模式客户端机器上的缓存没有正确刷新,没关系您所做的 schema.refresh() 调用
If one wants to access a custom attribute from a machine that is not part of the domain where the custom attribute resides (the credentials of the logged in user don't matter) one needs to pass the fully qualified name of the object is trying to access otherwise the schema cache on the client machine is not properly refreshed, nevermind all the schema.refresh() calls you make
在此处找到.鉴于对问题所做的更新,这听起来像是您的问题.
Found here. This sounds like your problem, given the updates made to the question.
- C#通过fleck实现wss协议的WebSocket多人Web实时聊天(附源码)
- 团队城市未满足要求:MSBuildTools12.0_x86_Path 存在
- 使用 MSBuild.exe 在发布模式下构建 C# 解决方案
- 当我发布 Web 应用程序时,AfterPublish 脚本不运行
- 构建时 T4 转换的产品仅在下一个构建中使用
- ASP.NET Core Application (.NET Framework) for Windows x64 only error in project.assets.json
- 新的 .csproj 格式 - 如何将整个目录指定为“链接文件"到子目录?
- 如何将条件编译符号(DefineConstants)传递给 msbuild
- MSBuild 支持 Visual Studio 2017 RTM 中的 T4 模板
- NuGet 包还原找不到包,没有源
