0

我在生产中有一个名为 Documents 的文档库。我编写了一个计时器作业,用于根据库中的列发送电子邮件。

在开发环境中一切都很好,但是 prod 中的计时器工作给了我例外。有任何想法吗?

        Entering monitored scope (Timer Job Corporate Policies - Reminder Emails)

作业定义 CorporatePolicyReminders.DailySchedule (ID 3586f4d2-1bc1-4770-b5b8-4c2c578ee8d5) 的 Execute 方法抛出异常。更多信息包括在下面。你调用的对象是空的。

异常堆栈跟踪:
在 CorporatePolicyReminders.CorporatePolicyReminders.SendCorporateReminder(SPWeb web)
at CorporatePolicyReminders.DailySchedule.Execute(Guid contentDbId)
at Microsoft.SharePoint.Administration.SPTimerJobInvokeInternal.Invoke(SPJobDefinition jd, Guid targetInstanceId, Boolean isTimerService, Int32& result)

离开监控范围(定时工作公司政策 - 提醒电子邮件)。执行时间=364.288198639771

SendCorporateReminers 方法

 public void SendCorporateReminder(SPWeb web)
{
    SPList lstComplaint = Helper.GetList(web, "Documents", Helper.ListType.Library);

    if (lstComplaint != null)
    {
        string query = "<Where><Eq><FieldRef Name='DocFormat' /><Value Type='Choice'>Policy</Value></Eq></Where>";
        SPListItemCollection colRecords = Helper.ExecuteQueryRecursive(lstComplaint, query, null, 2000);

        if (colRecords != null && colRecords.Count > 0)
        {
            foreach (SPListItem item in colRecords)
            {

                DateTime Expires = Helper.GetSPFieldDateTimeValue(item, "Expires");
                String Title = Helper.GetSPFieldTextValue(item, "Title");
                SPFieldUserValueCollection userResp = Helper.GetUsers(item, "Contact");
                TimeSpan totaldays = DateTime.Now.Date - Expires.Date;
                Int32 days = totaldays.Days;
                String emailtemplatekeyA = "AEmail" + days.ToString();
                String emailtemplatekeyB = "BEmail" + days.ToString();
                String respToEmail = String.Empty;


                if (userResp != null && userResp.Count > 0)
                {
                    foreach (SPFieldUserValue user in userResp)
                    {
                        if (!string.IsNullOrEmpty(respToEmail))
                            respToEmail += ",";
                        respToEmail += user.User.Email;
                    }
                }
                HandleEmails handleEmail = new HandleEmails();
                handleEmail.AddValueToPlaceholder(HandleEmails.EmailPlaceHolders.SendingTypeValue.EmailRecipient, PlaceHolder.USERRESP.ToString(), respToEmail);
                handleEmail.AddValueToPlaceholder(HandleEmails.EmailPlaceHolders.SendingTypeValue.OTHER, PlaceHolder.TITLE.ToString(), Title);
                handleEmail.AddValueToPlaceholder(HandleEmails.EmailPlaceHolders.SendingTypeValue.OTHER, PlaceHolder.EXPDT.ToString(), Expires.ToShortDateString());
                handleEmail.AddValueToPlaceholder(HandleEmails.EmailPlaceHolders.SendingTypeValue.OTHER, PlaceHolder.ID.ToString(), item.ID.ToString());
                handleEmail.SendMail(web, emailtemplatekeyA);
                handleEmail = new HandleEmails();
                handleEmail.AddValueToPlaceholder(HandleEmails.EmailPlaceHolders.SendingTypeValue.EmailRecipient, PlaceHolder.USERRESP.ToString(), respToEmail);
                handleEmail.AddValueToPlaceholder(HandleEmails.EmailPlaceHolders.SendingTypeValue.OTHER, PlaceHolder.TITLE.ToString(), Title);
                handleEmail.AddValueToPlaceholder(HandleEmails.EmailPlaceHolders.SendingTypeValue.OTHER, PlaceHolder.EXPDT.ToString(), Expires.ToShortDateString());
                handleEmail.AddValueToPlaceholder(HandleEmails.EmailPlaceHolders.SendingTypeValue.OTHER, PlaceHolder.ID.ToString(), item.ID.ToString());
                handleEmail.SendMail(web, emailtemplatekeyB);
            }
        }
    }
}`
4

1 回答 1

0

我找到了问题并解决了它。用户 ID 不再有效的人是联系文档的人(他在我正在创建计时器作业的库的联系列中)。因此,每当它尝试读取文档的联系人列时,计时器作业都会引发异常(对象引用未设置为对象的实例。)。我通过如下修改我的代码来解决这个问题,然后我从该列中删除了那个人。

    Helper.WriteUlsInformation("Item processing:" + i.ToString(), TraceSeverity.Verbose);
                    DateTime Expires = Helper.GetSPFieldDateTimeValue(item, "Expires");
                    Helper.WriteUlsInformation("Expires:" + Expires.ToString(), TraceSeverity.Verbose);
                    String Title = Helper.GetSPFieldTextValue(item, "Title");
                    Helper.WriteUlsInformation("Title:" + Title, TraceSeverity.Verbose);
                    SPFieldUserValueCollection userResp = Helper.GetUsers(item, "Contact");
                    Helper.WriteUlsInformation("UserResp read" , TraceSeverity.Verbose);
                    TimeSpan totaldays = DateTime.Now.Date - Expires.Date;
                    Int32 days = totaldays.Days;
                    Helper.WriteUlsInformation("Days:"+ days.ToString(), TraceSeverity.Verbose);
                    String emailtemplatekeyA = "AEmail" + days.ToString();
                    String emailtemplatekeyB = "BEmail" + days.ToString();
                    String respToEmail = String.Empty;
于 2014-06-10T20:14:35.550 回答