Everything appears to be working fine (apart from the fact that retrieving a specific attribute should be way easier than iterating around all existing attributes - not sure why it was designed this way), but when I try to disconnect I get
PlatformNotSupportedException: Thread abort is not supported on this platform.
The code is pretty much exactly as taken from the Novell documentation, apart from the fact that I am trying to just retrieve 2 specific attributes (name and logon time):
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();
And as soon as Disconnect
is called I get the error.
Has anyone else experienced this or know what might be going wrong?
stacktrace
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()
Novell developers have come up with the new version of Novell.Directory.Ldap.NETStandard which appears to be fully compatible with DotNet Core 2.0. I have changed my project reference to Novell.Directory.Ldap.NETStandard 3.0.0 version and now it is working fine.
Command Line for same is:
Install-Package Novell.Directory.Ldap.NETStandard -Version 3.0.0-beta4