private SearchResultCollection FindAll(bool findMoreThanOne)
        {
            //if it is not of valid searching type, then throw an exception
            if (SearchRoot == null)
            {
                Version adsVersion = GetAdsVersion();
                throw new InvalidOperationException(Res.GetString(Res.DSVersion, adsVersion.ToString()));
            }

            DirectoryEntry clonedRoot = null;

            if (assertDefaultNamingContext == null)
            {
                clonedRoot = SearchRoot.CloneBrowsable();
            }
            else
            {
                //SECREVIEW: If the SearchRoot was created by this object
                //                        it is safe to assert its browse permission to get
                //                        the inner IAds.
                DirectoryServicesPermission dsPermission = new DirectoryServicesPermission(
                    DirectoryServicesPermissionAccess.Browse, assertDefaultNamingContext);
                dsPermission.Assert();
                try {
                    clonedRoot = SearchRoot.CloneBrowsable();
                }
                finally {
                    DirectoryServicesPermission.RevertAssert();
                }
            }

            UnsafeNativeMethods.IAds adsObject = clonedRoot.AdsObject;
            if (!(adsObject is UnsafeNativeMethods.IDirectorySearch))
            {
                throw new NotSupportedException(Res.GetString(Res.DSSearchUnsupported, SearchRoot.Path));
            }

            UnsafeNativeMethods.IDirectorySearch adsSearch = (UnsafeNativeMethods.IDirectorySearch)adsObject;
            SetSearchPreferences(adsSearch, findMoreThanOne);

            string[] properties = null;
            if (PropertiesToLoad.Count > 0)
            {
                if (!PropertiesToLoad.Contains("ADsPath"))
                {
                    // if we don't get this property, we won't be able to return a list of DirectoryEntry objects!
                    PropertiesToLoad.Add("ADsPath");
                }
                properties = new string[PropertiesToLoad.Count];
                PropertiesToLoad.CopyTo(properties, 0);
            }

            IntPtr resultsHandle;

            if (properties != null)
            {
                adsSearch.ExecuteSearch(Filter, properties, properties.Length, out resultsHandle);
            }
            else
            {
                adsSearch.ExecuteSearch(Filter, null, -1, out resultsHandle);
                properties = new string[0];
            }

            SearchResultCollection result = new SearchResultCollection(clonedRoot, resultsHandle, properties, Filter);

            return(result);
        }