My team is using IIS Express in VS 2013 for debugging, I am getting the following error when querying Active Directory for AD Groups:
An exception of type 'System.Runtime.InteropServices.COMException' occurred in System.DirectoryServices.AccountManagement.dll but was not handled in user code
Additional information: Multiple connections to a server or shared resource by the same user, using more than one user name, are not allowed. Disconnect all previous connections to the server or shared resource and try again.
In the below code, the error is thrown by GetAuthorizationGroups()
.
Code:
public List<String> GetAllADGroups(String userName)
{
List<String> groups = new List<String>();
PrincipalContext ctx = new PrincipalContext(ContextType.Domain, this.Domain, this.LDapUserName, this.LDapPassword);
UserPrincipal user = UserPrincipal.FindByIdentity(ctx, userName);
// error on next line
foreach(Principal group in user.GetAuthorizationGroups().OrderBy(x => x.Name))
{
if (group.ContextType == ContextType.Domain && !String.IsNullOrEmpty(group.Name))
{
groups.Add(group.Name);
}
}
ctx.Dispose();
return groups;
}
Since this project is in TFS, I have 3 developers that run this code from their development servers. I am only getting this error on one of the servers. On the server that throws this error; when I run the site from IIS, the code works fine. So it leads me to think the issue is with one of the following:
- IIS Express
- Server Configuration
- VS 2013 Configuration
Any help is appreciated.