[Mono-list] Exception inside DirectorySearcher.FindOne
Adam Tauno Williams
adam@morrison-ind.com
Fri, 19 Nov 2004 10:36:43 -0500
I'm getting this exception from inside DirectorySearcher.FindOne
Index is less than 0 or more than or equal to the list count.
Parameter name: index
0
in <0x00058> System.Collections.ArrayList:get_Item (int)
in <0x00013> System.DirectoryServices.SearchResultCollection:get_Item
(int)
in <0x00054> (wrapper remoting-invoke-with-check)
System.DirectoryServices.SearchResultCollection:get_Item (int)
in <0x00029> System.DirectoryServices.DirectorySearcher:FindOne ()
in <0x00050> (wrapper remoting-invoke-with-check)
System.DirectoryServices.DirectorySearcher:FindOne ()
in <0x00320> whitemice.dseautomater.Preference:GetPreferenceValue
(string,string,string)
The code is
---------------------------------
DirectoryEntry dsAgent;
DirectorySearcher searchAgent;
SearchResult searchResult;
searchRoot = "LDAP://" + configuration.DSE + "/" + searchRoot;
dsAgent = new DirectoryEntry(searchRoot);
searchAgent = new DirectorySearcher(dsAgent);
searchAgent.SearchScope = SearchScope.OneLevel;
searchAgent.Filter = "(&(objectclass=morrisonapplicationpreference)" +
"(morrisonapplicationname=" + appName + ")" +
"(morrisonpreferencename=" + prefName + "))";
Console.WriteLine("Preference.GetPreferenceValue - Base=" +
searchRoot);
Console.WriteLine("Preference.GetPreferenceValue - Filter=" +
searchAgent.Filter);
try {
Console.WriteLine("searchAgent.FindOne");
searchResult = searchAgent.FindOne();
Console.WriteLine("searchAgent.FindOne - Complete");
------------------------------------
This works with a variety of DNs but with a few specific DNs as the
searchRoot (all of which exist) it dies with the noted exception. I
can't imagine that this is intended behaviour, if nothing is found then
FindOne should return a NULL value. (?)