Here’s a pointer that might save a few minutes (or hours!) of frustration if you hit the same problem as me. I was trying to extract the column (field) values from an SPListItem. Easy enough, you just use code like this:
public void ProcessItem(SPListItem item)
{
string name = item.Name;
string title = item.Title;
int id = item.ID;
// Do something else here
}
OK so far so good. I had this code within my project and ran it. As soon as it got the line where it assigns the name variable it threw an exception:
System.ArgumentException: Value does not fall within the expected range
I put a breakpoint in the function and ran it with the VS debugger attached to the W3WP process to hit the breakpoint. I began to check the item object in Visual Studio, and tried out a few expressions:
- item.Name and item.Title both threw the exception
- item["Name"] and item["Title"] both threw the exception as well
- item.ID and item["ID"] returned the correct values
- item.Fields.ContainsField(“Name”), item.Fields.ContainsField(“Title”) and item.Fields.ContainsField(“ID”) returned true
<FieldRef Name=’Name’><FieldRef Name=’Title’>