You get a 'System.ArgumentException: Value does not fall within the expected range" when you try to get the value of an SPListItem. Here is one solution to your problem!

This article will maybe help out some folks, because I didn't find the answer elsewhere.

I wanted to retrieve an SPListItem value, and I got the following error:

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.get_Item(Guid fieldId)

First, I didn't understand why this error was thrown on a such basic operation in SharePoint development.

Then going step by step trying to find a solution, I noticed that on my current SPList I had several field of type "Lookup" and "Person or Group", eleven exactly.

 

I finally found the solution in the Web Application settings.

Go to the Central Administration > Manage web applications > General Settings > Resource Throttling.

General Settings > Resource Throttling

Then take a look to the option named List View Lookup Threshold.

The description says: Specify the maximum number of Lookup, Person/Group, or workflow status fields that a database query can involve at one time.

List View Lookup Threshold

This option is the solution to our problem!

By default the value is set to 8. Just modify it depending on your needs. For my part I set it to eleven, and the error didn't show up again.

Just be carefull with this option, because it is used for performance reason. Don't raise it too much, just modify it to suit your needs.

 

Please feel free to comment or contact me if you have any question about this article.


Comments

Add a comment

(Will not be published)

Back to articles