Error occurred in deployment step ‘Activate Features’: Object reference not set to an instance of an object.

Do you get this error while deploying solution with a Feature Event Receiver through Visual Studio 2010. Well, I did while deploying a custom timer job solution which has a feature receiver to activate and deactivate the timer job feature.

Untitled

All I did immediately was that started googling as usual :D. Somewhere I got to know this error occurs if we have used SPContext class in our feature activate event receiver. But, when I checked my event receiver I did not use this class at all.

Then, I attached the solution to OWSTimer.exe and started debugging to trace the error. I then found that I have accessed the SPSite of the feature as its parent as shown below.

Untitled

And the scope of the feature was “Web” as shown below.

Untitled

The Parent property of a feature represents the object that represents the scope of the feature. So, in my case I have assigned the Parent property of the feature (Which is  SPWeb object) to the SPSite object instead and thus the mismatch caused the error while deploying. I know that this is not a very intellectually found fix, but still there could be few people like me who would immediately start googling for a solution :D.

Advertisements

17 thoughts on “Error occurred in deployment step ‘Activate Features’: Object reference not set to an instance of an object.

  1. Thanks it give me an immediate insight. But the web scope did not work for me instead it works only on the site scope. Its not clear why it doesnt run in parent hierarchy or maybe it has something to do with when I define the object web object to open a sub site instead of the root site.

    SPWebApplication webApplication = this.Parent as SPWebApplication;
    SPContentDatabase contentDb = webApplication.ContentDatabases[contentDbId];
    SPSite site = contentDb.Sites[0];
    SPWeb web = site.OpenWeb(“/projects/stp/package”); //access subsite

  2. Thanks for your post , I did this same thing 1 yr latter bt just forget this exact thing to change, so I was struggling for ths since last two days…………

    once again thanks

  3. In case Of event Receiver if you have not Given the Proerly. thn also you can get this error…If if you are working with Event Receiver so plzz check

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s