none
"You can not debug or run this application because the required version of the Microsoft Office application is not installed " C#.net4.5 and Outlook 2016 compatibility issue : Not able to run the C#.net solution RRS feed

  • Question

  • I am using outlook 2016 .We have received a legacy  developed on C#.net which was referenced to an older version of outlook.

    Requirement is to create a new ticket in remedy when we received a complaint from any users via an email on outlook. We have deleted the older reference and added the reference of Microsoft Office16.0 Object Library and pointed the target version of the C#.net code to Visual Studio 4.5 . Build is succeeded now . However , when we ran the application , it gives an error 

    "You can not debug or run this application because the required version of the Microsoft Office application is not installed "

    Source code to create a ticket is given below for reference.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net.Mail;
    using System.Text;
    using System.Windows.Forms;
    using System.Windows.Forms.VisualStyles;
    using System.Xml.Linq;
    using Outlook = Microsoft.Office.Interop.Outlook;
    using Office = Microsoft.Office.Core;
    
    namespace CheckMail
    {
        public partial class ThisAddIn
        {
            // private Outlook.Explorer currentExplorer = null;
            private Outlook.Inspectors OutlookInspectors = null;
            private Outlook.Inspector OutlookInspector = null;
            private Outlook.MailItem OutlookMailItem = null;
    
            private void ThisAddIn_Startup(object sender, System.EventArgs e)
            {
                //  currentExplorer = this.Application.ActiveExplorer();
    
                OutlookInspectors = Application.Inspectors;
    
                OutlookInspectors.NewInspector += new Microsoft.Office.Interop.Outlook.InspectorsEvents_NewInspectorEventHandler(OutlookInspectors_NewInspector);
                Application.ItemSend += new Microsoft.Office.Interop.Outlook.ApplicationEvents_11_ItemSendEventHandler(OutlookApplication_ItemSend);
    
    
                Application.NewMailEx += Application_NewMailEx;
    
                //Outlook.Selection selection = currentExplorer.Selection;
    
                //currentExplorer.ViewSwitch += currentExplorer_ViewSwitch;
                //currentExplorer.SelectionChange += new Outlook
                //    .ExplorerEvents_10_SelectionChangeEventHandler
                //    (CurrentExplorer_Event);
            }
    
            void Application_NewMailEx(string EntryIDCollection)
            {
                Outlook.NameSpace namespace1 = Application.GetNamespace("MAPI");
                Outlook.MAPIFolder folder = Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
                Outlook.MailItem mailItem = (Outlook.MailItem)namespace1.GetItemFromID(EntryIDCollection, folder.StoreID);
    
                if (mailItem != null)
                {
                    //var cata = mailItem.Importance;
    
                    //if (mailItem.Importance == Outlook.OlImportance.olImportanceLow)
                    //    mailItem.FlagIcon = Outlook.OlFlagIcon.olGreenFlagIcon;
                    //if (mailItem.FlagIcon == Outlook.OlFlagIcon.olYellowFlagIcon)
                    //    mailItem.FlagIcon = Outlook.OlFlagIcon.olYellowFlagIcon;
                    //if (mailItem.Importance == Outlook.OlImportance.olImportanceHigh)
                    //    mailItem.FlagIcon = Outlook.OlFlagIcon.olRedFlagIcon;
    
                    //mailItem.Save();
                }
            }
    
    
            void OutlookInspectors_NewInspector(Microsoft.Office.Interop.Outlook.Inspector Inspector)
            {
                OutlookInspector = (Outlook.Inspector)Inspector;
                if (Inspector.CurrentItem is Outlook.MailItem)
                {
                    OutlookMailItem = (Outlook.MailItem)Inspector.CurrentItem;
                }
    
            }
    
            void OutlookApplication_ItemSend(object Item, ref bool Cancel)
            {
                var mail = (Outlook.MailItem)Item;
                // Find the checked toggle button
                ThisRibbonCollection ribbonCollection = Globals.Ribbons[Globals.ThisAddIn.Application.ActiveInspector()];
                //Assign the importance of email here 
                if (ribbonCollection.ega.green.Checked)
                {
                    mail.FlagIcon = Outlook.OlFlagIcon.olGreenFlagIcon;
                    mail.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x10800003", 3);
                }
                if (ribbonCollection.ega.yellow.Checked)
                {
                    mail.FlagIcon = Outlook.OlFlagIcon.olYellowFlagIcon;
                    mail.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x10800003", 1);
                }
    
                if (ribbonCollection.ega.red.Checked)
                {
                    mail.FlagIcon = Outlook.OlFlagIcon.olRedFlagIcon;
                    mail.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x10800003", 2); // change the 4 to something like 600,601...etc to experiment
                 
                    /* "http://schemas.microsoft.com/mapi/proptag/0x10810003" */ //read
                }
    
               mail.Save();
    
            }
    
    
    
            private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
            {
                System.Runtime.InteropServices.Marshal.ReleaseComObject(OutlookInspectors);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(OutlookInspector);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(OutlookMailItem);
            }
    
            #region VSTO generated code
    
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InternalStartup()
            {
                this.Startup += new System.EventHandler(ThisAddIn_Startup);
                this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
            }
    
            #endregion
    
    
            private void CurrentExplorer_Event()
            {
                Outlook.MAPIFolder selectedFolder =
                    this.Application.ActiveExplorer().CurrentFolder;
                String expMessage = "Your current folder is "
                    + selectedFolder.Name + ".\n";
                String itemMessage = "Item is unknown.";
                try
                {
                    if (this.Application.ActiveExplorer().Selection.Count > 0)
                    {
                        Object selObject = this.Application.ActiveExplorer().Selection[1];
                        if (selObject is Outlook.MailItem)
                        {
                            Outlook.MailItem mailItem =
                                (selObject as Outlook.MailItem);
                            itemMessage = "The item is an e-mail message." +
                                " The subject is " + mailItem.Subject + ".";
                            mailItem.Display(false);
                        }
                        else if (selObject is Outlook.ContactItem)
                        {
                            Outlook.ContactItem contactItem =
                                (selObject as Outlook.ContactItem);
                            itemMessage = "The item is a contact." +
                                " The full name is " + contactItem.Subject + ".";
                            contactItem.Display(false);
                        }
                        else if (selObject is Outlook.AppointmentItem)
                        {
                            Outlook.AppointmentItem apptItem =
                                (selObject as Outlook.AppointmentItem);
                            itemMessage = "The item is an appointment." +
                                " The subject is " + apptItem.Subject + ".";
                        }
                        else if (selObject is Outlook.TaskItem)
                        {
                            Outlook.TaskItem taskItem =
                                (selObject as Outlook.TaskItem);
                            itemMessage = "The item is a task. The body is "
                                + taskItem.Body + ".";
                        }
                        else if (selObject is Outlook.MeetingItem)
                        {
                            Outlook.MeetingItem meetingItem =
                                (selObject as Outlook.MeetingItem);
                            itemMessage = "The item is a meeting item. " +
                                 "The subject is " + meetingItem.Subject + ".";
                        }
                    }
                    expMessage = expMessage + itemMessage;
                }
                catch (Exception ex)
                {
                    expMessage = ex.Message;
                }
                MessageBox.Show(expMessage);
            }
    
        }
    }
    

    Thursday, October 31, 2019 7:02 AM