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
}
}
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.
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).
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.
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....
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.
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.
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.
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With