Friday, May 31, 2013

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

Some times you get an error while deploying solution with a Feature Event Receiver through Visual Studio 2010.



The Main reason for this is the your Future.Parent is either SPSite, SPWeb or SPWebApplication. And you are trying to cast it in a wrong object.

If your feature scope is Site

SPSite oSite = Future.Parent As SPSite

If your Feature Scope is Web

SPWeb oWeb = Future.Parent As SPWeb

If your Feature Scope is WebApplication

SPWebApplication oApplication = Future.Parent As SPWebApplication

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.

No comments:

Post a Comment