Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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);

    }
share|improve this question
    
fixed my problem in another way so i don't have any solution for this right now –  Peter Mar 23 '12 at 13:06

1 Answer 1

up vote 1 down vote accepted

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))
share|improve this answer

Your Answer

 
discard

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.