Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intermittent unknown error from Active Directory

I'm using .Net account management libraries to access Active Directory to search the details of current http request user. My app pool runs with custom account and it also from the same domain. Server and users also belong to same domain.

public string GetEmployeeId(string SAMAccountName)
{
using (PrincipalContext domainContext = new PrincipalContext(ContextType.Domain))
{
using (UserPrincipal userprincipal = new UserPrincipal(domainContext))
{
userprincipal.SamAccountName = SAMAccountName; 
using (PrincipalSearcher ps = new PrincipalSearcher()) 
{
ps.QueryFilter = userprincipal; 
UserPrincipal user = ps.FindOne() as UserPrincipal;
return user.EmployeeId; 
}
}
}
}

Setup works perfectly but intermittently i get below error from AD.after sometime it works for the same user without any error.

Is there any way to check logs / events from the AD side to find the reason for this error.

System.Runtime.InteropServices.COMException (0x80005000): Unknown error >(0x80005000)

like image 756
Buddhika W Avatar asked Mar 28 '16 09:03

Buddhika W


1 Answers

I worked with a Microsoft Engineer for a long time to fix this so hopefully my solution can help others fix their problems.

First off the error code 0x80005000 referrers to an invalid ADSI pathname was passed, which wasn’t particularly helpfully.

We did a lot of tracing which was also not very helpful. Last thing we did was use Process Monitor to trace the Registry.

When the error occurred, I noticed a HIVE UNLOADED result happened (see screenshot) trace shot

Based on this we also found this error appearing in the event log.

Log Name:      Application 
Source:        Microsoft-Windows-User Profiles Service 
Date:          10/26/2009 8:22:13 AM 
Event ID:      1530 
Task Category: None 
Level:         Warning 
Keywords:      Classic 
User:          SYSTEM 
Computer:      SERVERNAME 
Description: 
Windows detected your registry file is still in use by other applications or services. The file will be unloaded now. The applications or services that hold your registry file may not function properly afterwards.  
DETAIL - 
1 user registry handles leaked from \Registry\User\S-1-5-21-1049297961-3057247634-349289542-1004_Classes: 
Process 2428 (\Device\HarddiskVolume1\Windows\System32\dllhost.exe) has opened key \REGISTRY\USER\S-1-5-21-1123456789-3057247634-349289542-1004_CLASSES

The engineer suggested this article https://support.microsoft.com/en-us/help/2287297/a-com-application-may-stop-working-on-windows-server-2008-when-a-user

Which seem to fix my problem.

like image 109
jon antoine Avatar answered Nov 06 '22 18:11

jon antoine