Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top