我创建了一个自定义定时器作业,并通过sharepoint中的一个特性事件来实现它。
当我试图激活它时,它显示了这个特殊的错误:
Object reference not set to an instance of an object. at TimerJobExample.MyFeatureReceiver.FeatureActivated(SPFeatureReceiverProperties properties) in C:Documents and Settingsadmin-shuklag.INFRADEVMy DocumentsVisual Studio 2008ProjectsTimerJobExampleTimerJobExampleMyFeatureReceiver.cs:line 22
at Microsoft.SharePoint.SPFeature.DoActivationCallout(Boolean fActivate, Boolean fForce)
at Microsoft.SharePoint.SPFeature.Activate(SPSite siteParent, SPWeb webParent, SPFeaturePropertyCollection props, Boolean fForce)
at Microsoft.SharePoint.SPFeatureCollection.AddInternal(Guid featureId, SPFeaturePropertyCollection properties, Boolean force, Boolean fMarkOnly)
at Microsoft.SharePoint.SPFeatureCollection.Add(Guid featureId)
at Microsoft.SharePoint.WebControls.FeatureActivator.BtnActivateFeature_Click(Object objSender, EventArgs evtargs)
at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
错误行在
下面高亮显示public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPSite site = properties.Feature.Parent as SPSite;
// make sure the job isn't already registered
//error line
**foreach (SPJobDefinition job in site.WebApplication.JobDefinitions)**
{
if (job.Name == List_JOB_NAME)
job.Delete();
}
SampleTimer listLoggerJob = new SampleTimer(List_JOB_NAME, site.WebApplication);
SPMinuteSchedule schedule = new SPMinuteSchedule();
schedule.BeginSecond = 0;
schedule.EndSecond = 59;
schedule.Interval = 5;
listLoggerJob.Schedule = schedule;
listLoggerJob.Update();
}
有什么问题吗?
根据你的特征接收器,我只能看到两种可能性:
- 再次检查feature.xml中的Scope属性是否设置为Site。如果它被设置为Web,当你试图使用
- 正如Janis所说,查看
MyCustomJob
构造器内部。确保所有变量都被正确初始化。
site
变量时,你会得到一个Object Reference not set
异常。问题在于功能的范围。它被设置为Web,并且要在此级别激活功能,您需要一个管理员帐户或具有更高权限的帐户。
您可以将应用程序池id添加到场管理帐户或