Was working on some code today, which was a timer job that used to work, but now doesn't. In the timer job, we had essentially something similar to the following:
SPChangeToken changeToken = list.ParentWeb.Properties["mychangetoken"]; SPChangeCollection changedItems = null; SPChangeQuery queryitem = new SPChangeQuery(false, true); queryitem.Item = true; queryitem.ChangeTokenStart = changeToken; newItemchanges = list.GetChanges(queryitem);
All the code above was working perfectly fine last year, but after coming back from holiday, we noticed the timer job would now keep throwing an exception when running:
The changeToken refers to a time before the start of the current change log.
It turns out that this happens because by default the change log only keeps entries for 60 days. (You can change this setting in the Resource Throttling section of the Web Application properties in Central Administration.) So therefore, after no changes were made in 60 days, the changeToken was now referring to a change log entry that had been purged.
So if you're getting an exception while working with the SharePoint changelog or changelog objects, make sure that you aren't attempting to use a changelog entry that doesn't exist any more. You can probably set the change log to never expire (but I imagine database space would very quickly become a concern for any reasonable amount of usage over a period of time), or just make sure that you handle / don't always expect to be able to get a full list of changes.