0
我有一個Outlook加載項(基本推送郵件到我們的應用程序),這是在一臺機器上返回問題(正常工作)。這只是沒有工作沒有錯誤,所以我們去了系統菜單,並將VSTO_SUPPRESSDISPLAYALERTS = 0推到屏幕。Outlook:未將對象引用設置爲對象的實例
當我然後跑了同步,我得到了以下
Object reference not set to an instance of an object.
************** Exception Text **************
System.NullReferenceException: Object reference not set to an instance of an object.
at MyAppOutlook.WaitingPopup.btnSyncOutlookInboxMail_Click(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
我跟不上,爲什麼這適用於大多數機器,但沒有這一項。該插件安裝並出現在其他機器的工具欄上,但它不起作用!
我已經檢查並重新安裝以下之前,我安裝了我們的插件:
- .NET3.5框架
- 主Interop 2007
注:大會展望2007年是
按照要求,該過程的代碼如下
Outlook.MAPIFolder outlookSentFolder = (Outlook.MAPIFolder)outlookObj.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail);
for (int i = 1; i <= outlookSentFolder.Items.Count; i++)
{
Outlook.MailItem mm = outlookSentFolder.Items[i] as Outlook.MailItem;
if (mm != null)
{
try
{
DateTime StartDate = new DateTime(((Outlook.MailItem)outlookSentFolder.Items[i]).SentOn.Year, ((Outlook.MailItem)outlookSentFolder.Items[i]).SentOn.Month, ((Outlook.MailItem)outlookSentFolder.Items[i]).SentOn.Day, ((Outlook.MailItem)outlookSentFolder.Items[i]).SentOn.Hour, ((Outlook.MailItem)outlookSentFolder.Items[i]).SentOn.Minute, 0);
if (StartDate > currentDate) // condition for current month mail sync
{
string attachs = "";
for (int j = 0; j < ((Outlook.MailItem)outlookSentFolder.Items[i]).Attachments.Count; j++)
{
attachs = ((Outlook.MailItem)outlookSentFolder.Items[i]).Attachments[j + 1].FileName.ToString() + "," + attachs;
}
ASCIIEncoding encoding = new ASCIIEncoding();
string postData = "userDBName=" + subsDBName;
postData += ("|MethodRequestName=addUpdateInboxMailFromOutlookToCRM");
postData += ("|loginid=" + username);
postData += ("|MailTo=" + ((Outlook.MailItem)outlookSentFolder.Items[i]).To);
postData += ("|MailCC=" + ((Outlook.MailItem)outlookSentFolder.Items[i]).CC);
postData += ("|MailFrom=" + ((Outlook.MailItem)outlookSentFolder.Items[i]).SenderEmailAddress);
postData += ("|MailSubject=" + ((((((Outlook.MailItem)outlookSentFolder.Items[i]).Subject).Replace("|", "")).Replace("#", "")).Replace("<", "")).Replace(">", ""));
postData += ("|MailBody=" + ((((((Outlook.MailItem)outlookSentFolder.Items[i]).Body).Replace("|", "")).Replace("#", "")).Replace("<", "")).Replace(">", ""));
postData += ("|MailSentOn=" + StartDate.ToString("MM/dd/yyyy hh:mm:ss"));//((Outlook.MailItem)outlookSentFolder.Items[i]).SentOn.ToString());
postData += ("|MailType=Sent");
postData += ("|MailAttach=" + attachs);
byte[] data = encoding.GetBytes(postData);
// Prepare web request...
HttpWebRequest myRequestSent = (HttpWebRequest)WebRequest.Create(reqURL + "Views/Subscription/OutlookDataService.aspx");
myRequestSent.Method = "POST";
myRequestSent.ContentType = "application/x-www-form-urlencoded";
myRequestSent.ContentLength = data.Length;
Stream newStream = myRequestSent.GetRequestStream();
// Send the data.
newStream.Write(data, 0, data.Length);
newStream.Close();
WebResponse responseHtmlSent = myRequestSent.GetResponse();
string xmlString = "";
using (StreamReader r = new StreamReader(responseHtmlSent.GetResponseStream()))
{
xmlString = xmlString + r.ReadToEnd();
}
responseHtmlSent.Close();
}
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show("Warning: " + ex.Message.ToString(), "Warning");
}
}
}
請誰能幫助,因爲我們設法讓儘可能得到這個錯誤?然而,我的理解是,這個錯誤通常意味着我們錯誤地引用了表,但是爲什麼它會在大多數其他機器上工作?
感謝
你有'btnSyncOutlookInboxMail_Click'的代碼嗎?該錯誤似乎來自該方法。 –
好的 - 上面添加的代碼。謝謝 – pipsqueek
@pipsqueak:那裏有很多代碼可能是原因。你有沒有試過編譯調試版本?或者添加一些調試語句?在不知道錯誤的行號的情況下,這將很難修復。 –