runtime: ASP.NET Core 2.0 using System.DirectoryServices.AccountManagement GroupPrincipal GetMembers Throws System.Exception: An operations error occurred.

Repo: https://github.com/benhysell/AspNetCoreGroupPrincipal

Manual steps to reproduce:

  • Create empty ASP.NET Core 2.0 Template, select React/Redux
  • Add Microsoft.Windows.Compatibility 2.0.0-preview1-25914-04 to the project via NuGet
  • Replace Index on HomeController.cs with the following to trigger a lookup of all users in a group:
public IActionResult Index()
{
    using (var pc = new PrincipalContext(ContextType.Domain, "YOUR_DOMAIN_HERE", "USERNAME", "PW"))
    {
        SortedSet<string> ldapResults;                               
        using (var gp = GroupPrincipal.FindByIdentity(pc, IdentityType.Name, "GROUP_TO_LOOKUP"))
        {
            ldapResults = gp == null ? null : new SortedSet<string>(gp.GetMembers(true).Select(u => u.SamAccountName));
        }
    }
    return View();
}
  • Start debugging

  • Throws the following:

fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[0]
      An unhandled exception has occurred while executing the request
System.Exception: An operations error occurred.

   at System.DirectoryServices.Interop.UnsafeNativeMethods.IAds.GetInfoEx(Object vProperties, Int32 lnReserved)
   at System.DirectoryServices.DirectoryEntry.RefreshCache(String[] propertyNames)
   at System.DirectoryServices.AccountManagement.RangeRetriever.GetNextChunk()
   at System.DirectoryServices.AccountManagement.RangeRetriever.MoveNext()
   at System.DirectoryServices.AccountManagement.ADDNLinkedAttrSet.GetNextEnum()
   at System.DirectoryServices.AccountManagement.ADDNLinkedAttrSet.MoveNextMemberEnum()
   at System.DirectoryServices.AccountManagement.ADDNLinkedAttrSet.MoveNext()
   at System.DirectoryServices.AccountManagement.FindResultEnumerator`1.MoveNext()
   at System.Linq.Enumerable.SelectEnumerableIterator`2.MoveNext()
   at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable`1 source, Int32& length)
   at System.Collections.Generic.SortedSet`1..ctor(IEnumerable`1 collection, IComparer`1 comparer)
   at System.Collections.Generic.SortedSet`1..ctor(IEnumerable`1 collection)
   at AspNetCoreGroupPrinicipal.Controllers.HomeController.Index() in C:\jobs\AspNetCoreGroupPrinicipal\AspNetCoreGroupPrinicipal\Controllers\HomeController.cs:line 21

Expected - Users are returned.

Environment - Windows 10 dotnet --version 2.1.2

[EDIT] Add C# syntax highlighting by @karelz

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 4
  • Comments: 25 (16 by maintainers)

Most upvoted comments

@tarekgh I just tested with version 2.0.6 and it worked!

Tested with a machine on and off the domain, both calls completed as expected.

I’m happy to close this issue at this time.

@tcables it looks you are using version 2.0.5 of the net core

Microsoft .NET Core Shared Framework Host

  Version  : 2.0.5

  Build    : 17373eb129b3b05aa18ece963f8795d65ef8ea54

You need 2.0.6 which has the fix.

@benhysell, are you able to tell if you still seeing the problem in 2.0.6? please make sure in your app to follow the instruction mentioned in the following comment too:

https://github.com/dotnet/corefx/issues/26292#issuecomment-362656712

Reading through this issues/status is this fix scheduled to be included in a servicing release like 2.0.6?

Yes, the fix should be included in 2.0.6

Is there a method to get a beta release of this fix?

Unfortunately no. you have to wait for the official servicing release.

@karelz you bet! ASP.NET full framework appears to work as expected.

Steps to reproduce:

  • Create ASP.NET WebAPI template with full .NET framework
  • Add reference to System.DirectoryServices.AccountManagement
  • Add test code to HomeController.cs here.
  • Debug application,
  • Works as expected, all users for the provided group are returned.