Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't Debug Application-Level Add-in for Outlook

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
    }
}
like image 746
Joker Avatar asked Oct 10 '12 12:10

Joker


People also ask

How do I debug Outlook Add Ins?

When your add-in loads in the Office host application, open the task pane. Return to Visual Studio Code and choose View > Debug or enter CTRL + SHIFT + D to switch to debug view. From the Debug options, choose Attach to Office Add-ins. Select F5 or choose Debug -> Start Debugging from the menu to begin debugging.

Why is my outlook add-in not working?

If an Outlook add-in running on Windows and using Internet Explorer is not working correctly, try turning on script debugging in Internet Explorer. Go to Tools > Internet Options > Advanced. Under Browsing, uncheck Disable script debugging (Internet Explorer) and Disable script debugging (Other).

How do I debug Microsoft Office?

Choose View > Run or enter Ctrl+Shift+D to switch to debug view. From the RUN AND DEBUG options, choose the Edge Legacy option for your host application, such as Outlook Desktop (Edge Legacy). Select F5 or choose Run > Start Debugging from the menu to begin debugging.

How do I debug an Outlook add-in?

Debugging Outlook Add in After your add-in is displayed in Outlook, you can debug your code by doing the following: 1 In Visual Studio, set breakpoints in your code. 2 In Outlook, interact with your add-in. 3 As breakpoints are hit in Visual Studio, step through the code as needed. See More....

How do I debug office add-ins in Visual Studio on a Mac?

You can't use Visual Studio to debug add-ins in Office on Mac. For information about debugging on a Mac, see Debug Office Add-ins on a Mac. Before you start debugging, review the properties of each project to confirm that Visual Studio will open the desired Office application and that other build and debug properties are set appropriately.

Is it possible to debug Outlook add-in with second factor?

The default is false, but the property has no practical effect. If you normally have to provide a second factor to login to the email account, you will be prompted to when you start debugging. Specifies the name of the user account in Exchange Server or Exchange Online that you want to use to test your Outlook add-in.

How do I debug code that runs in the add-in?

They each have a link to more detailed guidance. To debug code that runs in the Office.initialize function or an Office.onReady function that runs when the add-in opens, set your breakpoints, and then close and reopen the add-in. For more information about these functions, see Initialize your Office Add-in.


1 Answers

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"

like image 124
SliverNinja - MSFT Avatar answered Oct 10 '22 15:10

SliverNinja - MSFT