I know random errors don't really exist in our business, but I've got no clue as to why this method is not working.
In short, this method searches for some properties starting from the root domain. It works great, except that it randomly gives me the following exception:
Error
System.ApplicationException: No free/busy public folder found. Possible problem is wrong public folder URI or user doesn't have permission to read free/busy info.
Code
try
{
using (HostingEnvironment.Impersonate())
{
var entry = new DirectoryEntry("LDAP://rootDomain.com");
var searcher = new DirectorySearcher(string.Format("(&(sAMAccountName={0})(objectCategory=person))",searchAccount));
var primarysmtp = string.Empty;
var servername = string.Empty;
searcher.SearchRoot = entry;
searcher.SearchScope = SearchScope.Subtree;
searcher.PropertiesToLoad.Add("msExchHomeServerName");
searcher.PropertiesToLoad.Add("proxyAddresses");
//Exception happens here
results = searcher.FindAll();
}
}
finally
{
//Dispose entry, searcher & results
}
I've put some extra logging in this method, which tells me the following:
- It works for 20 times or more in a row
- At a random(?) moment, it fails 2-4 times in a row
- A minute later, everything works again.
I thought about authentication, but I don't see why that would make it fail so 'randomly'. Has anybody seen this kind of behavior before, or can someone give me some clues as to how to fix this?