首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >COMException未知错误(0x80005000) - DirectoryServices

COMException未知错误(0x80005000) - DirectoryServices
EN

Stack Overflow用户
提问于 2014-04-11 21:15:51
回答 2查看 6.8K关注 0票数 5

我在我的一个应用程序上遇到了一个错误,每个月都会发生几次,但本周已经发生了两次。当这种情况发生时,当第一个用户加载应用程序并开始工作(web应用程序,3-4个内部用户)时,始终是早上的第一件事。错误源于这个非常简单的方法,一旦失败,它将无法工作,直到我重新启动应用程序池。现在,我也在以其他方式查询AD,但这是用户早上开始工作时调用的第一个AD相关方法。

代码语言:javascript
复制
public DomainUser GetDomainUser(string userLoginName)
    {
        using (PrincipalContext context = new PrincipalContext(ContextType.Domain, this.DomainName))
        {
            using (UserPrincipal user = UserPrincipal.FindByIdentity(context, userLoginName))
            {
                // If user is null, the result is not a UserPrinciple
                if (user != null)
                {
                    string firstName = user.GivenName;
                    string middleName = user.MiddleName;
                    string lastName = user.Surname;
                    int empId = Convert.ToInt32(user.EmployeeId);
                    string emailAddr = user.EmailAddress;
                    string userName = user.SamAccountName;
                    DateTime? accountExp = user.AccountExpirationDate;

                    return new DomainUser
                    {
                        FirstName = firstName,
                        MiddleName = middleName,
                        LastName = lastName,
                        EmployeeId = empId,
                        Email = emailAddr,
                        UserName = userName,
                        AccountExpiration = accountExp
                    };
                }

                return null;
            }
        }
    }

所以this问题是密切相关的,但我的权限设置是正确的,代码99%的时间都可以工作,并且在应用程序池重新启动后将继续运行。

堆栈跟踪如下所示:

代码语言:javascript
复制
System.Runtime.InteropServices.COMException (0x80005000): Unknown error (0x80005000)
   at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
   at System.DirectoryServices.DirectoryEntry.Bind()
   at System.DirectoryServices.DirectoryEntry.get_AdsObject()
   at System.DirectoryServices.PropertyValueCollection.PopulateList()
   at System.DirectoryServices.PropertyValueCollection..ctor(DirectoryEntry entry, String propertyName)
   at System.DirectoryServices.PropertyCollection.get_Item(String propertyName)
   at System.DirectoryServices.AccountManagement.PrincipalContext.DoLDAPDirectoryInitNoContainer()
   at System.DirectoryServices.AccountManagement.PrincipalContext.DoDomainInit()
   at System.DirectoryServices.AccountManagement.PrincipalContext.Initialize()
   at System.DirectoryServices.AccountManagement.PrincipalContext.get_QueryCtx()
   at System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithTypeHelper(PrincipalContext context, Type principalType, Nullable`1 identityType, String identityValue, DateTime refDate)
   at System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithType(PrincipalContext context, Type principalType, String identityValue)
   at System.DirectoryServices.AccountManagement.UserPrincipal.FindByIdentity(PrincipalContext context, String identityValue)
   at ADWrapper.AdSearch.GetDomainUser(String userLoginName)

问题会是什么呢?内存泄漏?常见的模式是,当第一个用户开始使用应用程序时,这会在早上第一件事发生。

EN

回答 2

Stack Overflow用户

发布于 2019-11-06 03:20:46

我们也遇到过类似的问题。这是微软提供的解决方案。我希望这对某些人有帮助。

DirectoryEntry.Bind函数最终调用ADsOpenObject (https://docs.microsoft.com/en-us/windows/win32/api/adshlp/nf-adshlp-adsopenobject)该函数有一个“路由器”。路由器的初始化从注册表中枚举提供程序,例如“LdapNamespace”。它位于HKEY_CLASSES_ROOT\CLSID{228D9A82-C302-11cf-9AA4-00AA004A5691}\ProgID.还枚举了其他提供程序,如WinNT命名空间。

在跟踪中,查找这些注册表项时会返回错误。错误是,

ERROR_KEY_DELETED

1018 (0x3FA)

试图对已标记为删除的注册表项执行非法操作。

此错误可能是由于卸载进程用于其身份的用户配置文件造成的。

Windows用户配置文件服务强制卸载用户配置文件。这会导致流程出现问题。

我在w3wp.exe和dllhost.exe中看到过这一点,在这两个工具中,注册表配置文件是在过程完成之前卸载的。

这是我们为dllhost.exe做的一个关于这个问题的博客:https://blogs.msdn.microsoft.com/distributedservices/2009/11/06/a-com-application-may-stop-working-on-windows-server-2008-when-the-identity-user-logs-off/

您可能会在应用程序日志中看到如下描述的警告: Windows检测到您的注册表文件仍在由其他应用程序或服务使用。现在将卸载该文件。保存注册表文件的应用程序或服务以后可能无法正常运行。

我认为我们应该尝试一下博客中的解决方案/解决方法:

分辨率

作为一种解决方法,可能需要禁用此功能,这是默认行为。策略设置“在用户注销时不强制卸载用户注册表”计数Windows 2008的默认行为。启用时,Windows 2008不会强制卸载注册表,而是等到没有其他进程在使用用户注册表之后才将其卸载。

可以在组策略编辑器(gpedit.msc)中找到该策略

计算机配置->管理模板->系统-> UserProfiles

不要在用户注销时强制卸载用户注册表

将设置从“未配置”更改为“已启用”,这将禁用新的User Profile Service功能。

这种改变不应该有任何副作用。

票数 1
EN

Stack Overflow用户

发布于 2015-03-20 22:26:55

我为完全相同的问题挣扎了很长一段时间。我的解决方案实际上是安装feature IIS6元数据库兼容性。之后就没有问题了。下面是一些对我有帮助的文章

http://blogs.msdn.com/b/jpsanders/archive/2009/05/13/iis-7-adsi-error-system-runtime-interopservices-comexception-0x80005000-unknown-error-0x80005000.aspx

http://michaelwasham.com/2011/04/25/annoying-error-using-system-directoryservices-and-iis-app-pools/

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23013699

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档