connecting to a SharePoint online tenant (ctx works fine) I want to get all items which match a certain criteria (["Status"] == "Out of Synch") then load the ListItem Property "JobReference" at the same time but I keep getting Value does not fall within the expected range.

List sourceLibary = web.Lists.GetByTitle("Timer Job Source Library");
        string camlString = @"<View><ViewFields>< FieldRef Name = 'Status' />< FieldRef Name='JobReference' /></ViewFields><Query><Where><Eq>
            <FieldRef Name='Status' /><Value Type='Text'>Out of Synch</Value>
        CamlQuery query = new CamlQuery();
        query.ViewXml = camlString;
        ListItemCollection sourceItems = sourceLibary.GetItems(query);
        ctx.Load(sourceItems, si => si.Include(i => i.File, i => i["JobReference"]));

I create the field myself earlier in the code with no issues

string jobNameFieldXml = "<Field ID='{620CF30A-7551-4D8C-8FE6-75C0C96FA764}' Type='Text' Name='JobReference' StaticName='JobReference' DisplayName='Job Reference' />";

I have then tried changing ctx.Load() to the below but I always get errors?

ctx.Load(sourceItems, si => si.Include(i => i.File, i => i.File.ListItemAllFields.FieldValues["JobReference"]));


ctx.Load(sourceItems, si => si.Include(i => i.File, i => i.File.ListItemAllFields["JobReference"]));


ctx.Load(sourceItems, si => si.Include(i => i.File, i => i.FieldValues["JobReference"]));


So I found if I load the parts on the item separate it works? This makes the whole process very chatty? does anyone know why, maybe I misunderstand the return of the getItems() query or how .Include() works?


foreach (ListItem item in sourceItems)
            ctx.Load(item, i => i.File, i => i["JobReference"]);


  • I would suggest please use camel query build to form the Camel Query. there you can check whether your getting result or not. after this you use it your code. let me if it helps you. Feb 26, 2021 at 18:04

1 Answer 1


You have spacing in "< FieldRef Name = 'Status' />". Sometimes spacing creates a problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.