Mar/09
2010

Problems with SPFeatureCollection.Add


#1) SPFeature.Add ignores access denied failure


My major problem with SPFeatureCollection.Add is that it does not report failure due to access denied.

In the case of attempting to add a site collection feature, when the current user is not a site collection administrator, SPFeatureCollection.Add will create a new SPFeature object in the collection and return it, although the feature has not actually been activated on the site collection. I expected to be able to work around this by creating a new SPSite object (pointing to the same site collection) and checking its features collection, but no -- the new feature appears there as well.

For this reason, SharePoint Solution Installer does not report activation failures -- because they seem undetectable at the API level.

 

#2) SPFeatureCollection Add & Remove act differently than GUI if feature receiver not found

My second problem with SPFeatureCollection, Add and Remove both, is that they succeed silently in the face of feature receiver misconfiguration. From the GUI, activating or deactivating a feature missing its feature receiver assembly will fail, with a fairly descriptive error message (if custom errors are disabled). However, SPFeatureCollection Add and Remove will both actually succeed in this case.

This can be useful; it is a workaround to deactivate a feature which cannot be deactivated from the GUI.

4 comments
Comment from: Willie [Visitor]
WillieI think you have a good understanding of the topic. I think you have covered it well.
04/08/10 @ 07:49
Comment from: ufc betting [Visitor]
ufc bettingI see a lot of good articles here, what template do you use, is this random template ?
04/08/10 @ 08:10
Comment from: Lourdes [Visitor]
LourdesA friend referred to this post and i must say i thank him for it. Youve really given a good insight on the topic. Thanks again.
04/10/10 @ 02:54
Comment from: Unlock any phone [Visitor]
Unlock any phoneWell written article. Keep us posting.
08/09/10 @ 12:32

This post has 3 feedbacks awaiting moderation...

Leave a comment

Your email address will not be revealed on this site.

Your URL will be displayed.
(Line breaks become <br />)
(Name, email & website)
(Allow users to contact you through a message form (your email will not be revealed.)