Solution Package Retraction and SharePoint Feature Receiver: Uninstalling Event (Debugging)

Tags: SharePoint

One of the pet projects that I’m working on involves provisioning a document library to the RootWeb of a Site Collection and provisioning an Excel document to use as a template for some OpenXML SDK work I’m messing with (future post on this coming).  Anyway, the document library is really there just to provide a single xslx file as a template for some other code in the feature; so if the feature gets uninstalled, I want the document library to get uninstalled (deleted).  Deleting the document library is pretty straightforward, no problems there. 

The problem comes in when as administrator chooses to just retract/delete a solution package prior to deactivating the feature.  In this case features are never actually deactivated, they’re just deleted.  This means that the Deactivating event will never fire on your SPFeatureReceiver class.  The Uninstalling event will fire, however there’s no access to the SPFeature.Parent from the SPFeatureReceiverProperties object (its null)… which makes sense, its being retracted for the entire web application, not just the particular site/web.  For those curious, if you want to debug the Uninstalling event: 1) it fires when the solution package is retracted (not removed) and 2) you need to attach to the owstimer.exe process, not w3wp.  If you don’t see owstimer.exe in the attach to processes window, you need to check the box that says “Show Processes from All Users”

A solution for force deactivating a feature can be found at this post on the msdn forums; though I tend to disagree with MSFT on this in that I think you should just recommend users to follow best practices and deactivate features manually prior to solution package retraction.  This is where the PowerShell integration for SharePoint 2010 will really come in handy as the cleanup code found in that post should really be in a Command Line App or, better yet, a Powershell integration.

Sidebar: I’ve turned comment moderation on and I’ll be honest that I don’t have a ton of time to actually moderate them.  I do love comments, but in the meantime if you have any questions about stuff I put on this space, feel free to email me at jpm at jonathanpmast dot com.  Apparently the spammer are better at indexing my site than search engines… (prolly my fault at not being an SEO samurai)

Edit: grammar, spelling fail

Add a Comment