I found out this is because system reported error at wrong line. Problem solved.
System.NullReferenceException: Object reference not set to an instance of an object. at CheckRfqStatus.Program.StartCheckingRFQStatus(Int32 startDateVariable) in D:\PRIVACY\Program.cs:line 121
Line 121:
if (null == mapiFolderArchive.Folders["Sent Email to Vendor"]) { logger.Debug("9"); }
Here are the relevant code:
MAPIFolder mapiFolderArchive = (MAPIFolder)outlook.Session.Folders[archiveFolderName].Folders["Inbox"].Parent;
if (null == (MAPIFolder)outlook.Session.Folders[archiveFolderName]) { logger.Debug("33"); }
if (null == (MAPIFolder)outlook.Session.Folders[archiveFolderName].Folders["Inbox"]) { logger.Debug("35"); }
if (null == (MAPIFolder)outlook.Session.Folders[archiveFolderName].Folders["Inbox"].Parent) { logger.Debug("4"); }
MAPIFolder archiveSentEmailToVendorFolder = mapiFolderArchive.Folders["Sent Email to Vendor"];
if (null == mapiFolderArchive) { logger.Debug("7"); }
if (null == mapiFolderArchive.Folders) { logger.Debug("8"); }
//Below is line 121
if (null == mapiFolderArchive.Folders["Sent Email to Vendor"]) { logger.Debug("9"); }
My logger didn't log anything at all, why is line 121 still have null error?
Based on all the advices, I redo my code.
MAPIFolder mapiFolderArchive = (MAPIFolder)outlook.Session.Folders[archiveFolderName].Folders["Inbox"].Parent;
MAPIFolder defaultSentToVendorFolder = mapiFolderPurchase.Folders["Sent Email to Vendor"];
if (mapiFolderArchive.Folders != null)
{
if (mapiFolderArchive.Folders["Sent Email to Vendor"] != null)
{
MAPIFolder archiveSentEmailToVendorFolder = mapiFolderArchive.Folders["Sent Email to Vendor"];
//Now system said this line below got null reference exception error.
if (archiveSentEmailToVendorFolder != null)
Why is if (archiveSentEmailToVendorFolder != null)
got null reference exception when I already checked if (mapiFolderArchive.Folders["Sent Email to Vendor"] != null)
?