簡體   English   中英

值不能為 null 參數名稱:destinationTimeZone

[英]Value cannot be null Parameter Name: destinationTimeZone

I have a function that basically sends automated email to my company email address, it has 6 parameters that I need to make it work, the issue is every time I call it to make it run it always throw this exception 'System.ArgumentNullException' in mscorlib.dll 我還讓它在控制台中顯示異常以獲取更多詳細信息(見下圖)。 我想知道是什么觸發了異常以及如何修復它。 (見下面的代碼)


在此處輸入圖像描述


送Email Function

public static void SendEmail(Microsoft.Office.Interop.Outlook.Application Application, List<string> screenshotLocations, bool bi6Accessible, bool bi7Accessible, bool bi8Accessible, bool detailedReportingAccessible)
        {
            string recipients = ConfigurationManager.AppSettings["ToEmail"];
            StringBuilder mailBodyText = new StringBuilder();
            TimeZoneInfo India_Standard_Time = null;
            DateTime dateTime_Indian = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, India_Standard_Time);
            TimeZoneInfo Phillipines_Standard_Time = null;
            DateTime dateTime_PH = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, Phillipines_Standard_Time);
            Microsoft.Office.Interop.Outlook.MailItem mail = null;
            Microsoft.Office.Interop.Outlook.Recipients mailRecipients = null;
            Microsoft.Office.Interop.Outlook.Recipient mailRecipient = null;
            var logFile = @"C:\Users\kent.harvey.p.abrio\Documents\Visual Studio 2015\Projects\SConsoleApplication1\SConsoleApplication1\SanityCheckApplication\ScreenShots\loggers.txt";

            try
            {
                mail = Application.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem)
                    as Microsoft.Office.Interop.Outlook.MailItem;

                mail.Subject = string.Format("Hourly Sanity Check Automated Mail - {0} IST / {1} PHT", dateTime_Indian.ToString("yyyy-MM-dd HH:mm"), dateTime_PH.ToString("yyyy-MM-dd HH:mm"));
                //Attach Logs


                mail.Attachments.Add(logFile);
                //Attach Screenshots
                foreach (string item in screenshotLocations)
                {
                    //add the screenshot name
                    mail.Attachments.Add(item);
                }
                //Create Mail Body
                if (bi6Accessible)
                    mailBodyText.AppendLine("Tableau Accessibility : Bi6 reports are visible. Please refer to attached screenshot.\n");
                else
                    mailBodyText.AppendLine("Tableau Accessibility : Bi6 reports are not visible in IMP. Please take appropriate actions.\n");
                if (bi7Accessible)
                    mailBodyText.AppendLine("Qlik Accessibility : Bi7 reports are visible. Please refer to attached screenshot.\n");
                else
                    mailBodyText.AppendLine("Qlik Accessibility : Bi7 reports are not visible in IMP. Please take appropriate actions.\n");
                if (bi8Accessible)
                    mailBodyText.AppendLine("Qlik-Sense Accessibility : Bi8 reports are visible. Please refer to attached screenshot.\n");
                else
                    mailBodyText.AppendLine("Qlik-Sense Accessibility : Bi8 reports are not visible in IMP. Please take appropriate actions.\n");
                if (detailedReportingAccessible)
                    mailBodyText.AppendLine("Detailed reporting Accessibility : Offline reports list are visible. Please refer to attached screenshot.\n");
                else
                    mailBodyText.AppendLine("Detailed reporting Accessibility : Offline reports list are not visible in IMP. Please take appropriate actions.\n");

                mail.Body = Convert.ToString(mailBodyText);
                //Add and Resolve Recipient List
                mailRecipients = mail.Recipients;
                mailRecipient = mailRecipients.Add(recipients);
                mailRecipient.Resolve();

                if (mailRecipient.Resolved)
                {
                    mail.Send();
                    string firstLog = ("Email send to : " + recipients);
                    File.WriteAllText(logFile, firstLog);
                }
                else
                {

                    string secondLog = ("There is no such record in your address book.");
                    File.WriteAllText(logFile, secondLog);
                }
            }
            catch (System.Exception ex)
            {
                //Logger("An exception is occured in the code of add-in.");
                //Logger(ex.Message);
                //Logger("Stack Trace :" + ex.StackTrace);
                string thirdLog = ("An exception is occured in the code of add-in." + ex.StackTrace);
                File.WriteAllText(logFile, thirdLog);
            }
            finally
            {
                if (mailRecipient != null) Marshal.ReleaseComObject(mailRecipient);
                if (mailRecipients != null) Marshal.ReleaseComObject(mailRecipients);
                if (mail != null) Marshal.ReleaseComObject(mail);
            }
        }

我就是這樣稱呼它的。

 try
 {
     SendEmail(Application, screenshotLocations, bi6Accessible, bi7Accessible, bi8Accessible, detailedReportingAccessible);

  }
  catch (System.Exception e)
  {
     Console.WriteLine(e.Message);
     ieDriver.Quit();
  }

換行

            TimeZoneInfo India_Standard_Time = null;
            DateTime dateTime_Indian = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, India_Standard_Time);
            TimeZoneInfo Phillipines_Standard_Time = null;
            DateTime dateTime_PH = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, Phillipines_Standard_Time);

            TimeZoneInfo India_Standard_Time = TimeZoneInfo.FindSystemTimeZoneById("India Standard Time");
            DateTime dateTime_Indian = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, India_Standard_Time);
            TimeZoneInfo Phillipines_Standard_Time = TimeZoneInfo.FindSystemTimeZoneById("Taipei Standard Time");
            DateTime dateTime_PH = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, Phillipines_Standard_Time);

菲律賓使用台北的原因在http://www.pinoy-web-application.com/blogs/c-how-to-get-time-zone-date-and-time-in-the-philippines/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM