0

I am writing code for feature activated code. But when I try to deploy my solution through VS 2010 it says deploy failed Error on feature activation : object reference not set to an instance of an object.
I can't debug since it doesn't allow me to deploy the code. I have tried to put

System.Diagnostics.Debugger.Break();

at the beginning of my FeatureActivated method. Any thoughts?

  public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            using(SPSite spSite = new SPSite(HttpContext.Current.Request.Url.ToString()))
           {
                using(SPWeb spWeb = spSite.OpenWeb())
                {

                }

           }
        }
1

Instructions for Visual Studio 2010:

Click on "Project" in the menu and then " properties"

Click on "SharePoint on the left, and then switch the Active Deployment Configuration to "No Activation".

Start debugging, and then activate the feature manually through the UI. You should now be able to debug through your feature activation steps if you have set breakpoints appropriately.

0

If you feature is Site scoped, you can get the SPSite object as following:

var spSite = properties.Feature.Parent as SPSite;

If you feature is Web scoped, you can get the SPSite object as following:

var spSite = (properties.Feature.Parent as SPWeb).Site;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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