SharePoint exception “Value does not fall within the expected range.”

05/02/2013

Today I had one of the usual SharePoint guessing games with their little too generic exceptions.

I had some code, in a common library that tried to access the data of a field of the the type SPFieldType.User on a SPListItem. This worked fine when logged in as farm administrator, but failed for all other users with the following exception:

{System.ArgumentException: Value does not fall within the expected range.
at Microsoft.SharePoint.SPFieldMap.GetColumnNumber(String strFieldName, Boolean bThrow)
at Microsoft.SharePoint.SPListItemCollection.GetColumnNumber(String groupName, Boolean bThrowException)
at Microsoft.SharePoint.SPListItemCollection.GetRawValue(String fieldname, Int32 iIndex, Boolean bThrow)
at Microsoft.SharePoint.SPListItem.GetValue(SPField fld, Int32 columnNumber, Boolean bRaw, Boolean bThrowException)
at Microsoft.SharePoint.SPListItem.GetValue(String strName, Boolean bThrowException)
at Microsoft.SharePoint.SPListItem.get_Item(String fieldName)

At first I thought it was some access denied exception I got since I was working on a site restored from another environment. But after some googleing and head-against-wall-banging I found out that it was a resource throttling error. The default setting for web applications is to only allow 8 lookup columns per list, which wasn’t enough in my case.

To increase it, go to the webapplication in central administration, and select “Resource Throttling” under “General Settings”.

Or use the following powershell:

$app = get-spwebapplication
$app.MaxQueryLookupFields = 16
$app.Update()

The reason why it didn’t fail for my farm account, is that the resource throttling is not enforced for system accounts.