Unable to load list item properties for a couple of items using CSOM call.
The relevant code snippet below:
try
{
Web site = clientContextWrapper.ClientContext.Site.OpenWebById(scomItemVersionWrapper.SCOMListWrapper.ParentSiteID);
List list = site.Lists.GetById(scomItemVersionWrapper.SCOMListWrapper.Id);
listItem = list.GetItemByUniqueId(scomItemVersionWrapper.UniqueId);
clientContextWrapper.ClientContext.Load(listItem);
clientContextWrapper.ClientContext.Load(listItem.File);
if (scomItemVersionWrapper.SCOMListWrapper.EnableAttachments && scomItemVersionWrapper.HaveAttachment)
{
var attachmentFolderName = scomItemVersionWrapper.IntId.ToString();
listAttachmentFolder = list.RootFolder.Folders.GetByUrl("Attachments");
clientContextWrapper.ClientContext.Load(listAttachmentFolder.Folders, fc => fc.Where(folder => folder.Name == attachmentFolderName).Include(f => f.Name, f => f.Files));
clientContextWrapper.ClientContext.Load(listItem.AttachmentFiles);
}
if (scomItemVersionWrapper.VersionID != Int32.MinValue)
{
clientContextWrapper.ClientContext.Load(listItem.Versions, f => f.Include(x => x.VersionId, x => x["Editor"], x => x.FileVersion.ID, x => x.FileVersion.Length, x => x.FileVersion.CreatedBy, x => x.FileVersion.Url, x => x.FileVersion.CheckInComment));
}
m_clientContextPool.ExecuteQueryWithIncrementalRetry(clientContextWrapper, "SharePointConnector.prepareItemForWriting item data", item.FullPath);
}
catch (Exception ex)
{
logger.LogE("Error loading list item properties required for archiving.", Logger.With("exceptionMsg", ex.ToString()));
throw;
}
This code throws the exception "Microsoft.SharePoint.Client.ServerException: Value does not fall within the expected range." for a couple of items in a customer site.
Is there any SharePoint online setting that causes this? Or is there any coding error in the above snippet? (The code works perfectly for all other sites in different testing environments.)