title: Read all users from AD using Novell.Directory.Ldap.NETStandard
body: <p>I need to read all users from the AD. Here is code that I am using:</p>
  <pre><code>using Novell.Directory.Ldap;
  using Novell.Directory.Ldap.Controls;
  using System.Linq;
  
  namespace LdapTestApp
  {
      class Program
      {
          static void Main()
          {
              LdapConnection ldapConn = new LdapConnection();
              ldapConn.SecureSocketLayer = true;
              ldapConn.Connect(HOST, PORT);
  
              try
              {
                  var cntRead = 0;
                  int? cntTotal = null;
                  var curPage = 0;
  
                  ldapConn.Bind(USERNAME, PASSWORD);
  
                  do
                  {
                      var constraints = new LdapSearchConstraints();
                      constraints.SetControls(new LdapControl[]
                      {
                          new LdapSortControl(new LdapSortKey(&quot;sn&quot;), true),
                          new LdapVirtualListControl(&quot;sn=*&quot;, 0, 10)
                      });
  
                      ILdapSearchResults searchResults = ldapConn.Search(
                          &quot;OU=All Users,DC=homecredit,DC=ru&quot;,
                          LdapConnection.ScopeSub,
                          &quot;(&amp;(objectCategory=person)(objectClass=user))&quot;,
                          null,
                          false,
                          constraints
                      );
  
                      while (searchResults.HasMore() &amp;&amp; ((cntTotal == null) || (cntRead &lt; cntTotal)))
                      {
                          ++cntRead;
  
                          try
                          {
                              LdapEntry entry = searchResults.Next();
                          }
                          catch (LdapReferralException)
                          {
                              continue;
                          }
                      }
  
                      ++curPage;
                      cntTotal = GetTotalCount(searchResults as LdapSearchResults);
                  } while ((cntTotal != null) &amp;&amp; (cntRead &lt; cntTotal));
              }
              finally
              {
                  ldapConn.Disconnect();
              }
          }
  
          private static int? GetTotalCount(LdapSearchResults results)
          {
              if (results.ResponseControls != null)
              {
                  var r = (from c in results.ResponseControls
                           let d = c as LdapVirtualListResponse
                           where (d != null)
                           select (LdapVirtualListResponse)c).SingleOrDefault();
                  if (r != null)
                  {
                      return r.ContentCount;
                  }
              }
  
              return null;
          }
      }
  }
  </code></pre>
  <p>I used this question <a href="https://stackoverflow.com/questions/55208799/page-ldap-query-against-ad-in-net-core-using-novell-ldap">Page LDAP query against AD in .NET Core using Novell LDAP</a> as basis.
  Unfortunatelly I get this exception when I am trying to recieve the very first entry:</p>
  <pre><code>&quot;Unavailable Critical Extension&quot;
  000020EF: SvcErr: DSID-03140594, problem 5010 (UNAVAIL_EXTENSION), data 0
  </code></pre>
  <p>What am I doing wrong?</p>