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

  • is it only a masterpage and a stylesheet or anything else? Feature receiver, content type etc.
    – Dennis G
    Jan 26, 2011 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! Jan 26, 2011 at 17:47
  • Can you share the code that throws this error?
    – CodeThug
    Jan 26, 2011 at 19:05

1 Answer 1


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.

  • Thanks, that makes sense to me. I'm now scoping the feature to Site. Jan 26, 2011 at 17:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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