title: Ldap query only returning 1000 users... yes I am using paging
body: <p>I have a simple GetStaff function that should retrieve all users from active directory.  We have over a 1000 users so the directory searcher is using paging because the default for the AD MaxPageSize is 1000.  </p>
  
  <p>Currently the search works 'sometimes' when I build and sends back all 1054 users, and other times it only sends back 1000.  If it works once, it works all the time.  If it fails once, it fails all the time.  I have set everything in using statements to make sure the objects are destroyed, but it still doesn't always seem to respect the PageSize attribute.  By default if the PageSize attribute is set, the searcher should use a SizeLimit of 0.  I have tried leaving the size limit out, setting it to 0, and setting it to 100000 and the unstable result is the same.  I have also tried lowering the PageSize to 250 and get the same unstable results.  Currently I am trying changing the ldap policy on the server to have a MaxPageSize of 10000 and I am still receiving 1000 users with the search PageSize to 10000 also.  Not sure what I am missing here, but any help or direction would be appreciated.</p>
  
  <pre class="lang-cs prettyprint-override"><code>    public IEnumerable&lt;StaffInfo&gt; GetStaff(string userId)
      {
          try
          {
              var userList = new List&lt;StaffInfo&gt;();
  
              using (var directoryEntry = new DirectoryEntry("LDAP://" + _adPath + _adContainer, _quarcAdminUserName, _quarcAdminPassword))
              {
                  using (var de = new DirectorySearcher(directoryEntry)
                  {
                      Filter = GetDirectorySearcherFilter(LdapFilterOptions.AllUsers),
                      PageSize = 1000,
                      SizeLimit = 0
                  })
                  {
  
                      foreach (SearchResult sr in de.FindAll())
                      {
                          try
                          {
                              var userObj = sr.GetDirectoryEntry();
                              var staffInfo = new StaffInfo(userObj);
  
                              userList.Add(staffInfo);
                          }
                          catch (Exception ex)
                          {
                              Log.Error("AD Search result loop Error", ex);
                          }
                      }
                  }
              }
  
              return userList;
          }
          catch (Exception ex)
          {
              Log.Error("AD get staff try Error", ex);
              return Enumerable.Empty&lt;StaffInfo&gt;();
          }
  
      }
  </code></pre>