My symptoms and System.DirectoryServices.AccountManagement stack trace are exactly the same as While trying to retrieve the authorization groups, an error (5) occurred except that I get an error 110 which docs explain as ERROR_OPEN_FAILED: The system cannot open the device or file specified.
In my situation, this functionality was working one day and stopped working the next day within an ASP.NET v4 application. I am using an AD service account that I've created in order to establish a connection to AD. The service account has admin privileges to a specific 开发者_如何学PythonOU further down in the directory.
I've narrowed the exception down to a call made to the AuthzInitializeContextFromSid native function inside the System.DirectoryServices.AccountManagement.AuthZSet constructor. It is not clear to me why this fails and since user.GetGroups works for me (per the answer given in the other SO link), I'll put my research on hold for now.
Does anyone else have any thoughts on what might be occurring?
Error 5 usually means you are having an ERROR_ACCESS_DENIED win32 error. That can happen if you're accessing a downlevel API that can only be queried with administrative rights or if the object you are accessing has ACLs that deny access from the process token your program is running at.
In simple words: try running your app elevated. If it works, you had insufficient access rights when running without elevation.
精彩评论