调用时发生 PlatformNotSupportedException LdapConnetion.Disconnect

PlatformNotSupportedException when calling LdapConnetion.Disconnect

一切似乎都工作正常(除了检索特定属性应该比遍历所有现有属性更容易的事实 - 不确定为什么这样设计),但是当我尝试断开连接时我得到

PlatformNotSupportedException: Thread abort is not supported on this platform.

该代码与从 Novell 文档中获取的代码几乎完全相同,除了我试图仅检索 2 个特定属性(名称和登录时间)之外:

var users = new List<User>();

// Creating an LdapConnection instance 
LdapConnection ldapConn= new LdapConnection();

//Connect function will create a socket connection to the server
ldapConn.Connect("DOMAIN.com",389);

//Bind function will Bind the user object Credentials to the Server
ldapConn.Bind("DOMAIN\_Bassi","password");

// Searches in the Marketing container and return all child entries just below this
//container i.e. Single level search
LdapSearchResults lsc=ldapConn.Search("OU=Users,OU=MCS,OU=AU,OU=COMPANY,DC=DOMAIN,DC=com",
                LdapConnection.SCOPE_ONE,
                "objectClass=*",
                null,
                false);

while (lsc.hasMore())
{
    var user = new User();

    LdapEntry nextEntry = null;
    try 
    {
        nextEntry = lsc.next();
    }
    catch(LdapException e) 
    {
        Console.WriteLine("Error: " + e.LdapErrorMessage);
        // Exception is thrown, go for next entry
        continue;
    }
    Console.WriteLine("\n" + nextEntry.DN);

    LdapAttributeSet attributeSet = nextEntry.getAttributeSet();
    System.Collections.IEnumerator ienum =  attributeSet.GetEnumerator();

    var atts = attributeSet.ToArray().ToList();

    while(ienum.MoveNext())
    {
        LdapAttribute attribute=(LdapAttribute)ienum.Current;
        if(attribute.Name == "sAMAccountName")
        {
            user.UserName = attribute.StringValue;
        } 
        else if(attribute.Name == "lastLogonTimestamp")
        {
            user.LastLogon = DateTime.FromFileTime(long.Parse(attribute.StringValue));
        }
    }

    users.Add(user);
}

ldapConn.Disconnect();

一旦调用 Disconnect,我就会收到错误消息。

有没有其他人遇到过这种情况或知道可能出了什么问题?

堆栈跟踪

System.Threading.Thread.Abort()


Novell.Directory.Ldap.Connection.Dispose(bool disposing, string reason, int semaphoreId, InterThreadException notifyUser)


Novell.Directory.Ldap.Connection.destroyClone(bool apiCall)


Novell.Directory.Ldap.LdapConnection.Disconnect()


LogonChecker.Managers.ActiveDirectory.GetADUsers() in ActiveDirectory.cs
- 
64.                    }
65.                }
66.
67.                users.Add(user);
68.            }
69.
70.            ldapConn.Disconnect();
71.
72.            return users;
73.
74.            // LdapConnection ADconn = new LdapConnection();
75.            // ADconn.Connect("DOMAIN.com", 389);
76.            // ADconn.Bind("DOMAIN\_Bassie", "password");


LogonChecker.Controllers.UserController+<Index>d__2.MoveNext() in UserController.cs
- 
20.        }
21.
22.        // GET: User
23.        public async Task<IActionResult> Index()
24.        {
25.            var ad = new ActiveDirectory();
26.            var users = ad.GetADUsers();
27.
28.            return View(users);
29.            // return View(await _context.User.ToListAsync());
30.        }
31.
32.        // GET: User/Details/5


System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()


System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)


System.Runtime.CompilerServices.TaskAwaiter.GetResult()


Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker+<InvokeActionMethodAsync>d__12.MoveNext()


System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()


System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)


Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker+<InvokeNextActionFilterAsync>d__10.MoveNext()


System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()


Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)


Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)


Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker+<InvokeInnerFilterAsync>d__14.MoveNext()


System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()


System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)


Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker+<InvokeNextResourceFilter>d__22.MoveNext()


System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()


Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)


Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)


Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker+<InvokeFilterPipelineAsync>d__17.MoveNext()


System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()


System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)


Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker+<InvokeAsync>d__15.MoveNext()


System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()


System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)


Microsoft.AspNetCore.Builder.RouterMiddleware+<Invoke>d__4.MoveNext()


System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()


System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)


Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware+<Invoke>d__7.MoveNext()

它抛出此错误的原因是因为.NET Core 不支持Thread.Abort()。 该库将需要更新以使用不同的机制(我相信 CancellationToken 是推荐的方法)

Novell 开发人员提出了 new version of Novell.Directory.Ldap.NETStandard 似乎与 DotNet Core 2.0 完全兼容。我已将项目参考更改为 Novell.Directory.Ldap.NETStandard 3.0.0 版本,现在运行正常。

相同的命令行是:

Install-Package Novell.Directory.Ldap.NETStandard -Version 3.0.0-beta4