7

This is the first time I am using .NET to create an Application-level Add-in for Outlook. By using a tutorial I wrote down some code and it was successfully build, but I was unable to debug the code. While debugging an alert box displays saying:

You cannot run or debug this project because the required version of the Microsoft application is not installed.

I am using Visual Studio 2010 and MS Office 2007. In order to debug the code what shall I do? Can I make any change in code so that I can debug it.

here is the code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Outlook = Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;
using Microsoft.Office.Interop.Outlook;
namespace OutlookAddIn1
{

    public partial class ThisAddIn
    {
        Outlook.Inspectors inspectors;
        event InspectorsEvents_NewInspectorEventHandler NewInspector;


        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            inspectors = this.Application.Inspectors;
            inspectors.NewInspector +=
            new Microsoft.Office.Interop.Outlook.InspectorsEvents_NewInspectorEventHandler(Inspectors_NewInspector); 
        }

        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {

        }
        void Inspectors_NewInspector(Microsoft.Office.Interop.Outlook.Inspector Inspector)
        {
            Outlook.MailItem mailItem = Inspector.CurrentItem as Outlook.MailItem;
            if (mailItem != null)
            {
                if (mailItem.EntryID == null)
                {
                    mailItem.Subject = "This text was added by using code";
                    mailItem.Body = "This text was added by using code";
                }

            }
        }
        #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
    }
}
SliverNinja - MSFT
  • 31,051
  • 11
  • 110
  • 173
Joker
  • 830
  • 2
  • 14
  • 30

1 Answers1

20

The issue is not your code - it is a misconfiguration of your project file and which MS Office version you have installed. See related SO post regarding editing DebugInfoExeName in the csproj to match the proper Office version.

Office Version | Version Number
---------------+-----------------
    2007       |   12.0
    2010       |   14.0
    2013       |   15.0
    2016       |   16.0

For MS Office 2007, your project file DebugInfoExeName should be:

DebugInfoExeName="#Software\Microsoft\Office\12.0\Outlook\InstallRoot \Path#outlook.exe"

Community
  • 1
  • 1
SliverNinja - MSFT
  • 31,051
  • 11
  • 110
  • 173