SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have created a feature to apply a custom masterpage and stylesheet to my SharePoint web application. This feature is scoped to Web Application level.

My problem is that if I try and activate it through the SharePoint admin site's "Manage web application features" page, I get the following error:

Object reference not set to an instance of an object. at Microsoft.SharePoint.SPModuleElement.ElementActivated(SPFeaturePropertyCollection props, SPSqlCommand sqlcmdAppendOnly, SPWebApplication webApp, SPSite site, SPWeb web, Boolean fForce) at Microsoft.SharePoint.Administration.SPElementDefinitionCollection.ProvisionModules(SPFeaturePropertyCollection props, SPSite site, SPWeb web, Boolean fForce) at Microsoft.SharePoint.Administration.SPElementDefinitionCollection.ProvisionElements(SPFeaturePropertyCollection props, SPWebApplication webapp, SPSite site, SPWeb web, Boolean fForce) at Microsoft.SharePoint.SPFeature.ProvisionElements(SPFeaturePropertyCollection props, SPWebApplication webapp, SPSite site, SPWeb web, Boolean fForce) at Microsoft.SharePoint.SPFeature.Activate(SPSite siteParent, SPWeb webParent, SPFeaturePropertyCollection props, Boolean fForce) at Microsoft.SharePoint.SPAdminFeatureCollection.Add(Guid featid, SPFeaturePropertyCollection props, Boolean fForce) at Microsoft.SharePoint.SPFeatureCollection.AddInternal(Guid featureId, SPFeaturePropertyCollection properties, Boolean force, Boolean fMarkOnly) at Microsoft.SharePoint.SPFeatureCollection.Add(Guid featureId) at Microsoft.SharePoint.WebControls.FeatureActivator.BtnActivateFeature_Click(Object objSender, EventArgs evtargs) at System.Web.UI.WebControls.Button.OnClick(EventArgs e) at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

If I scope the feature to site level it works correctly.

Does anyone know what might be causing this?

Thanks, Robert

share|improve this question
is it only a masterpage and a stylesheet or anything else? Feature receiver, content type etc. – Dennis G Jan 26 '11 at 15:20
There's a configuration page as well. I think I need to read up on feature receivers, I'm pretty new to SharePoint dev! – RobertDougan Jan 26 '11 at 17:47
Can you share the code that throws this error? – CodeThug Jan 26 '11 at 19:05
up vote 2 down vote accepted

How do you apply the master page?

If you're doing this via Feature Receiver, then at Web Application level, the feature is activated for all Site Collections in that web app - ie: the Feature won't have a specific SPSite object in it's context for you to access and set the masterpage.

ie: masterpages can't be deployed this way.

Scope it to Site Collection, and ensure that the Package is deployed to the web applications you want it available to. Thus, the feature will be available to activate in each Site Collection within that Web Application.

share|improve this answer
Thanks, that makes sense to me. I'm now scoping the feature to Site. – RobertDougan Jan 26 '11 at 17:45

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.