#StackBounty: #development #csom #getchanges Why does Changes API return changes for Lists that do not exist?

Bounty: 50

I am using the Changes API to fetch changes:

ChangeQuery cq = new ChangeQuery(true, true);
cq.ChangeTokenStart = new ChangeToken();
cq.ChangeTokenStart.StringValue = string.Format("1;1;{0};{1};-1", site.Id, DateTime.Now.AddDays(-1).ToUniversalTime().Ticks.ToString());
cq.FetchLimit = 1000;
cq.RecursiveAll = false;
cq.GroupMembershipAdd = false;
cq.GroupMembershipDelete = false;
cq.RoleAssignmentAdd = false;
cq.RoleAssignmentDelete = false;
cq.RoleDefinitionUpdate = false;
cq.RoleDefinitionAdd = false;
cq.RoleDefinitionDelete = false;
cq.User = false;
cq.SystemUpdate = false;
cq.Group = false;
cq.SecurityPolicy = false;
cq.Update = false;
cq.Add = true;
cq.DeleteObject = false;
cq.Item = true;
cq.File = false;
cq.Folder = false;
cq.Alert = false;
cq.Web = false;
cq.LatestFirst = false;//Sorting

while (cq.ChangeTokenStart != null)
    var changes = context.Site.GetChanges(cq);
    Change lastChangeItem = null;

    foreach (Microsoft.SharePoint.Client.Change change in changes)
        Console.WriteLine(string.Format("Chnage is {0}", change.ChangeType));

        if (change is ChangeItem)
            ChangeItem changeItem = (ChangeItem)change;
            List list = context.Web.Lists.GetById(changeItem.ListId);
            Console.Write("List {0}", list.Id);

        lastChangeItem = change;

    if (lastChangeItem == null)
        cq.ChangeTokenStart = null;
        cq.ChangeTokenStart = lastChangeItem.ChangeToken;

But I’m getting errors when trying to do this. Some of the ChangeItem values refer to lists that do not exist:

The page you selected contains a list that does not exist.  It may have been deleted by another user.

I did not delete any lists during my test. Just added new site and some new documents to a document library.

So in summary, I’m getting “ghost” lists and list items that do not actually exist as far as I can tell.

What are these “ghost ChangeItem” values? where are they coming from and should I be doing something to filter them?

Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.