The property or field has not been initialized. It has not been requested or the request has not been executed

Nerobov Andrey 96 Reputation points
2021-03-12T09:17:23.94+00:00

Hello!
I sometimes have a problem wnen I work with CSOM for SharePoint Online.
I make this request :
var list = context.Web.Lists.GetById(listid);
item = list.GetItemById(id);
context.Load(item);
context.ExecuteQueryRetry();
context.Load(item, x => x, x => x.HasUniqueRoleAssignments, x => x.Id, x => x.ContentType.Id,
x => x.RoleAssignments, x => x.RoleAssignments.Include(y => y.RoleDefinitionBindings, y => y.PrincipalId));
context.ExecuteQueryRetry();
After that I try get LookupId :
((FieldLookupValue)item[TaskList.Expertise]).LookupId;
and I catch the error :
The property or field has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested. Stack: at Microsoft.SharePoint.Client.ListItem.GetFieldValue(String fieldName)
I don't understand, why doesn't this error happen all the time?It happens about twice a week.
I use Microsoft.SharePoint.Client, Version=16.1.0.0 and OfficeDevPnP.Core, Version=3.20.2004.0
Thanks!

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,593 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Amos Wu-MSFT 4,051 Reputation points
    2021-03-15T02:45:36.923+00:00

    The item has been loaded in the clientContext, and this problem should not occur.
    I test with SharePoint.Client, Version=16.1.0.0 and OfficeDevPnP.Core, Version=3.26.2010.0. And I do not reproduce your issue.
    77517-image.png


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. Nerobov Andrey 96 Reputation points
    2021-03-15T07:29:19.05+00:00

    @Amos Wu-MSFT Thank! I don't reproduce too.This error occurs in runtime only and it happens about twice a week. This situations is critical for me, because error occurs in big service. Service works for many people,but all requests are made by one service account. Maybe there are restrictions on the number of requests from one account?


  3. Nerobov Andrey 96 Reputation points
    2021-03-17T08:35:01.86+00:00

    @Amos Wu-MSFT Do you have a source code of ExecuteQueryRetry()?