Error on Activate Features on deploying SharePoint Skin
-
07-12-2019 - |
سؤال
Error occurred in deployment step 'Activate Features': Object reference not set to an instance of an object. I just can't figure out where the error is occuring. Found some blog posts concerning the issue but they weren't really helpful either.
public class Feature1EventReceiver : SPFeatureReceiver
{
// Uncomment the method below to handle the event raised after a feature has been activated.
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPSite parent = (SPSite)properties.Feature.Parent;
SPFeatureProperty property = properties.Feature.Properties["MasterPage"];
string str = property.Value;
SPFeatureProperty property2 = properties.Feature.Properties["SearchMasterPage"];
string str2 = property2.Value;
if (!string.IsNullOrEmpty(str))
{
str = SPUrlUtility.CombineUrl(parent.ServerRelativeUrl, "_catalogs/masterpage/" + str);
str2 = SPUrlUtility.CombineUrl(parent.ServerRelativeUrl, "_catalogs/masterpage/" + str2);
foreach (SPWeb web in parent.AllWebs)
{
if (((web.WebTemplate == "SRCHCENTERLITE") || (web.WebTemplate == "SRCHCEN")) || (web.WebTemplate == "SRCHCENTERFAST"))
{
web.MasterUrl = str;
web.CustomMasterUrl = str2;
}
else
{
web.MasterUrl = str;
web.CustomMasterUrl = str;
}
web.Update();
}
}
}
// Uncomment the method below to handle the event raised before a feature is deactivated.
public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
{
SPSite parent = (SPSite) properties.Feature.Parent;
string str = SPUrlUtility.CombineUrl(parent.ServerRelativeUrl, "_catalogs/masterpage/v4.master");
string str2 = SPUrlUtility.CombineUrl(parent.ServerRelativeUrl, "_catalogs/masterpage/minimal.master");
foreach (SPWeb web in parent.AllWebs)
{
if (((web.WebTemplate == "SRCHCENTERLITE") || (web.WebTemplate == "SRCHCEN")) || (web.WebTemplate == "SRCHCENTERFAST"))
{
web.CustomMasterUrl = str2;
}
else
{
web.MasterUrl = str;
web.CustomMasterUrl = str;
}
web.Update();
}
SPListCollection lists = parent.RootWeb.Lists;
SPList list = lists["Metro UI Themes"];
lists.Delete(list.ID);
}
المحلول
Do you know what line exactly it's erroring out on? You may be able to find this in the logs, or at least a better idea of where it's breaking. If I had to guess I'd say it's not finding one of the master pages. Have you tried switching this line:
if (!string.IsNullOrEmpty(str))
To this:
if (!string.IsNullOrEmpty(str) && !string.IsNullOrEmpty(str2))
لا تنتمي إلى sharepoint.stackexchange