Outlook Addin Exception
-
Hi everyone, I developed an Outlook Addin that is supposed to open a certain application depending on the subject of the Email that I receive. The app works fine but after clicking OK to all MessageBoxes, I get the ff error: 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 Outlook_Drag_Try.ThisApplication.ThisApplication_Startup(Object sender, EventArgs e) in C:\Inetpub\wwwroot\DRAGGER\Outlook_Drag_Try\Outlook_Drag_Try\ThisApplication.cs:line 31 at Microsoft.Office.Tools.Outlook.Application.OnStartup() at Outlook_Drag_Try.ThisApplication.FinishInitialization() in C:\Inetpub\wwwroot\DRAGGER\Outlook_Drag_Try\Outlook_Drag_Try\ThisApplication.Designer.cs:line 65 at Microsoft.VisualStudio.Tools.Applications.Runtime.AppDomainManagerInternal.ExecutePhase(String methodName) at Microsoft.VisualStudio.Tools.Applications.Runtime.AppDomainManagerInternal.ExecuteCustomizationStartupCode() at Microsoft.VisualStudio.Tools.Applications.Runtime.AppDomainManagerInternal.ExecuteEntryPointsHelper() at Microsoft.VisualStudio.Tools.Applications.Runtime.AppDomainManagerInternal.Microsoft.VisualStudio.Tools.Applications.Runtime.IExecuteCustomization2.ExecuteEntryPoints() ************** Loaded Assemblies ************** Here is my code: string filter = "ecs"; Outlook.NameSpace outlookNameSpace = this.GetNamespace("MAPI"); //Outlook.MAPIFolder inbox = outlookNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox); Outlook.MAPIFolder inbox = this.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox); /*Retrieve and count unread messages from Inbox */ Outlook.Items items = inbox.Items; Outlook.Items unreadItems = inbox.Items.Restrict("[Unread]=true"); MessageBox.Show(string.Format("The number of Unread items in Inbox = {0}", unreadItems.Count)); // If the mail item matches the specified filter, // open The Dragger application foreach (Outlook.MailItem mail in items) { //if the mail's subject has ecs, open The Dragger if (mail.Subject.ToUpper().Contains(filter.ToUpper())) { //Open The Dragger MainForm main = new MainForm(); main.Sho
-
Hi everyone, I developed an Outlook Addin that is supposed to open a certain application depending on the subject of the Email that I receive. The app works fine but after clicking OK to all MessageBoxes, I get the ff error: 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 Outlook_Drag_Try.ThisApplication.ThisApplication_Startup(Object sender, EventArgs e) in C:\Inetpub\wwwroot\DRAGGER\Outlook_Drag_Try\Outlook_Drag_Try\ThisApplication.cs:line 31 at Microsoft.Office.Tools.Outlook.Application.OnStartup() at Outlook_Drag_Try.ThisApplication.FinishInitialization() in C:\Inetpub\wwwroot\DRAGGER\Outlook_Drag_Try\Outlook_Drag_Try\ThisApplication.Designer.cs:line 65 at Microsoft.VisualStudio.Tools.Applications.Runtime.AppDomainManagerInternal.ExecutePhase(String methodName) at Microsoft.VisualStudio.Tools.Applications.Runtime.AppDomainManagerInternal.ExecuteCustomizationStartupCode() at Microsoft.VisualStudio.Tools.Applications.Runtime.AppDomainManagerInternal.ExecuteEntryPointsHelper() at Microsoft.VisualStudio.Tools.Applications.Runtime.AppDomainManagerInternal.Microsoft.VisualStudio.Tools.Applications.Runtime.IExecuteCustomization2.ExecuteEntryPoints() ************** Loaded Assemblies ************** Here is my code: string filter = "ecs"; Outlook.NameSpace outlookNameSpace = this.GetNamespace("MAPI"); //Outlook.MAPIFolder inbox = outlookNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox); Outlook.MAPIFolder inbox = this.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox); /*Retrieve and count unread messages from Inbox */ Outlook.Items items = inbox.Items; Outlook.Items unreadItems = inbox.Items.Restrict("[Unread]=true"); MessageBox.Show(string.Format("The number of Unread items in Inbox = {0}", unreadItems.Count)); // If the mail item matches the specified filter, // open The Dragger application foreach (Outlook.MailItem mail in items) { //if the mail's subject has ecs, open The Dragger if (mail.Subject.ToUpper().Contains(filter.ToUpper())) { //Open The Dragger MainForm main = new MainForm(); main.Sho
Walaza wrote:
at Outlook_Drag_Try.ThisApplication.ThisApplication_Startup(Object sender, EventArgs e) in C:\Inetpub\wwwroot\DRAGGER\Outlook_Drag_Try\Outlook_Drag_Try\ThisApplication.cs:line 31
Could you point out this line in your code above?
----- Formerly MP(2) If atheism is a religion, then not collecting stamps is a hobby. -- Unknown
-
Walaza wrote:
at Outlook_Drag_Try.ThisApplication.ThisApplication_Startup(Object sender, EventArgs e) in C:\Inetpub\wwwroot\DRAGGER\Outlook_Drag_Try\Outlook_Drag_Try\ThisApplication.cs:line 31
Could you point out this line in your code above?
----- Formerly MP(2) If atheism is a religion, then not collecting stamps is a hobby. -- Unknown
Hi Le Centriste, This is Line 31: //if the mail's subject is ecs, open The Dragger Application LINE 31--> if (mail.Subject.ToUpper().Contains(filter.ToUpper())) { //Open The Dragger MainForm main = new MainForm(); main.ShowDialog(); } else { MessageBox.Show("No New Messages For ECS!!!"); }
Mvelo Walaza Jnr Developer Telkom SA
-
Hi Le Centriste, This is Line 31: //if the mail's subject is ecs, open The Dragger Application LINE 31--> if (mail.Subject.ToUpper().Contains(filter.ToUpper())) { //Open The Dragger MainForm main = new MainForm(); main.ShowDialog(); } else { MessageBox.Show("No New Messages For ECS!!!"); }
Mvelo Walaza Jnr Developer Telkom SA
I would check for nullity of either
mail.Subject
orfilter
.----- Formerly MP(2) If atheism is a religion, then not collecting stamps is a hobby. -- Unknown