What is the reason for the below exception message in CSOM code which I received when querying for data from SharePoint Online?
Value does not fall within the expected range.
Code sample:
public static void siteCountHelper(String siteUrl, CredentialSharePoint c, List<SiteCountHelper> results)
{
try
{
ClientContext client = new ClientContext(siteUrl);
client = sharepointOnline(client, c);//setting credential
var web = client.Web;
client.Load(web, w => w.Webs, w => w.ServerRelativeUrl);
var lists = client.LoadQuery(client.Web.Lists.Where(temp => temp.BaseType != BaseType.DocumentLibrary));
var documentLibraries = client.LoadQuery(client.Web.Lists.Where(temp => temp.BaseType == BaseType.DocumentLibrary));
client.ExecuteQuery();
SiteCountHelper helper = new SiteCountHelper
{
websCount = web.Webs.Count,
listsCount = lists.Count(),
documentLibrariesCount = documentLibraries.Count()
};
results.Add(helper);
if (web.Webs.Count != 0)
{
String tempUrl = siteUrl.Replace(web.ServerRelativeUrl, "");
foreach (var w in web.Webs)
{
String mainUrl = tempUrl + w.ServerRelativeUrl;
siteCountHelper(mainUrl, c, results); //recursive call
}
}
}
catch (Exception e)
{
log(e.Message);
}
}
client.ExecuteQuery();line after each line from the top of the code to pinpoint where the error is.