I'm going to assume that you have a Site scoped feature and that your NullReferenceException
is being caused by you attempting to cast properties.Feature.Parent as SPWeb
.
If my assumption about your feature being Site scoped is correct you can't get access to an SPWeb
the way you are trying. Try this instead:
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPSite siteCollection = properties.Feature.Parent as SPSite;
if (siteCollection != null)
{
SPWeb web = siteCollection.RootWeb;
// Rest of your code here.
}
}