I have a tool to update all items in SP (link replacement). The tool works most of the time but sometimes it throws me an ArgumentException
("Value does not fall within the expected range.").
Here is the code how I iterate and try to access the value:
foreach (SPList list in web.Lists)
{
foreach (SPListItem item in list.Items)
{
foreach (SPField field in list.Fields)
{
if (!field.ReadOnlyField)
{
if (item.Fields.Contains(field.Id) && item[field.Id] != null)
{
The exception is thrown at item[field.Id]
and I don't see why. The field is clearly in the item fields collection as the item.Fields.Contains(field.Id)
returns true
. Also of course the field.Id is a normal Guid.
Am I making some logical error here?