Skip to main content
1 of 3
Luis Valencia
  • 5.2k
  • 22
  • 119
  • 219

Value does not fall within the expected range when iterating over all fields

I have a custom page that copies items from one list in one site to another, and its failing with the exception above.

I tried checking the field using sharepoint manager but I didnt find anything strange. Tthe field where its failing its a managed metadata column

the strange thing its that the exception is shown when checking if the field[internalname] is != null

foreach (SPListItem item in listItems)
                            {

                                SPListItem targetItem = destinationList.Items.Add();
                                foreach (SPField field in item.Fields)
                                {
                                    if (!field.ReadOnlyField && field.InternalName != "Attachments")
                                    {
                                        if (item[field.InternalName] != null)
                                        {
                                            
                                            
Luis Valencia
  • 5.2k
  • 22
  • 119
  • 219