Question : System.InvalidOperationExc<wbr />eption: The value for the property PageSize cannot be set

I have a routine that searches ldap..its always worked fine...until today I canceled out of teh routine during a dev debug test... it was working fine and I closed the app in the middle of the routine.. tried to run it again it again and now I keep getting this error.

System.InvalidOperationException: The value for the property PageSize cannot be set.
   at System.DirectoryServices.DirectorySearcher.DoSetSearchPrefs(IDirectorySearch adsSearch, AdsSearchPreferenceInfo[] prefs)
   at System.DirectoryServices.DirectorySearcher.SetSearchPreferences(IDirectorySearch adsSearch, Boolean findMoreThanOne)
   at System.DirectoryServices.DirectorySearcher.FindAll(Boolean findMoreThanOne)
   at System.DirectoryServices.DirectorySearcher.FindAll()


This is my code fr the search


                DirectoryEntry entry = omnifrmwk.InternalClasses.LDAPMethods.getLDAPDirectoryEntry();


                DirectorySearcher search = new DirectorySearcher(entry);
                search.PropertiesToLoad.Add("uid");
                search.PropertiesToLoad.Add("company");
                           //search.PropertiesToLoad.Add("costcenterdescription");
                search.PropertiesToLoad.Add("mail");
   
                search.Filter = "(&(objectCategory=person)(objectClass=user)(!(userAccountControl:1.2.840.113556.1.4.803:=2)))";
                search.PageSize = 1000;
                foreach (SearchResult result in search.FindAll())
                {
                    DirectoryEntry de = result.GetDirectoryEntry();

                    string uid = de.Properties["uid"].Value.ToString();

Answer : System.InvalidOperationExc<wbr />eption: The value for the property PageSize cannot be set

Wow... there is nothing wrong with what you've posted.

I can only imagine that perhaps the LDAP session has remained open...  I'd check the Task Manager for any stray processes or COM connections to your LDAP server

Random Solutions  
 
programming4us programming4us