<p>An obscure puzzle, but it's driving me absolutely nuts:</p>

<p>I'm creating a custom Information Management Policy in MOSS. I've implemented IPolicyFeature, and my policy feature happily registers itself by configuring a new SPItemEventReceiver. All new items in my library fire the events as they should, and it all works fine.</p>

<p>IPolicyFeature also has a method ProcessListItem, which is supposed to retroactively apply the policy to items that were already in the library (at least, it's supposed to do that for as long as it keeps returning <code>true</code>). Except it doesn't. It only applies the policy to the <strong><em>first</em></strong> item in the library, and I have absolutely no idea why.</p>

<p>It doesn't seem to be throwing an exception, and it really does return true from processing that first item, and I can't think what else to look at. Anyone?</p>

<p>Edit: Cory's answer, below, set me on the right track. Something else was indeed failing -- I didn't find out what, since my windbg-fu isn't what it should be, but I suspect it was something like "modifying a collection while it's being iterated over". My code was modifying the SPListItem that's passed into ProcessListItem, and then calling SystemUpdate on it; as soon as I changed the code so that it created its own variable (pointing at the exact same SPListItem) and used that, the problem went away...</p>

[{'answer_id': 46797, 'author': 'Cory Foy', 'author_id': 4083, 'author_profile': 'https://Stackoverflow.com/users/4083', 'pm_score': 2, 'selected': True, 'text': '<p>There\'s only a couple of things I can think of to try. First, are you developing on the box where you might be able to use Visual Studio to debug? So just stepping through it.</p>\n\n<p>Assuming that\'s not the case - what I\'d do is fire up WinDBG and attach it to the process just before I registered the policy. Turn on first chance exceptions so that it breaks whenever they occur. you can do that by issuing the command "sxe clr" once it is broken in. Here\'s a little more info about WinDBG:</p>\n\n<p><a href="http://blogs.msdn.com/tess/archive/2008/06/05/setting-net-breakpoints-in-windbg-for-applications-that-crash-on-startup.aspx" rel="nofollow noreferrer"><a href="http://blogs.msdn.com/tess/archive/2008/06/05/setting-net-breakpoints-in-windbg-for-applications-that-crash-on-startup.aspx" rel="nofollow noreferrer">http://blogs.msdn.com/tess/archive/2008/06/05/setting-net-breakpoints-in-windbg-for-applications-that-crash-on-startup.aspx</a></a></p>\n\n<p>What I\'d do is then watch for First Chance exceptions to be thrown, and do a !PrintException to see what is going on. My guess is that there is an exception being thrown somewhere that is causing the app to stop processing the other items. </p>\n\n<p>What does the logic look like for your ProcessListItem? Have you tried just doing a return true to make sure it works?</p>\n'}, {'answer_id': 47352, 'author': 'Matt Bishop', 'author_id': 4301, 'author_profile': 'https://Stackoverflow.com/users/4301', 'pm_score': 0, 'selected': False, 'text': "<p>Some nice ideas there, thanks. The Visual Studio debugger wasn't showing an exception (and I've wrapped everything in try/catch blocks just in case), but I hadn't thought of trying Windbg...</p>\n"}]
['https://Stackoverflow.com/questions/46692', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4301/']