Object reference not set to an instance of an object on feature deployment- Can't deploy even
-
29-09-2020 - |
Question
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())
{
}
}
}
Solution
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.
OTHER TIPS
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;