I have a list item with one field Classes which is a multiple choice lookup. I want to implement an ASPX page which contains a ListBox which is filled with values from the Classes field. The following method does that:
private void GetSelectedClasses()
{
SPFieldLookupValueCollection currentSelection;
using (SPWeb web = this.Web)
{
ClassesListBox.Items.Clear();
currentSelection = item["Classes"] as SPFieldLookupValueCollection;
foreach (SPFieldLookupValue value in currentSelection)
{
ClassesListBox.Items.Add(value.LookupValue);
}
}
}
This method works fine if I run/debug/deploy it with my account which is a SharePoint admin. However, when I run it under User1 account, which has contribute permissions on the site and the list which contains the list item, I get the strange error:
System.ArgumentException: Value does not fall within the expected range.
The error is happening in the line
currentSelection = item["Classes"] as SPFieldLookupValueCollection;
When I promote the User1 to Full Control permissions user or even site collection administrator, I am still getting the error. The ArgumentException appears to be firing because the field named Classes doesn't exist, allegedly. This is of course not true, because checking the item fields does list it and it all works well with my default account.
Could anyone help me out? I feel quite desperate. Thanks!