Vista 2016 plugin AttachmentSelection Issue

I created an Outlook add-in for the selected attachment to get information about the attachment. and its working tone in Outlook 2010. But when I create it for Outlook 2016, it becomes zero.

Below is the code in ThisAddIn.cs: -

private void ThisAddIn_Startup(object sender, System.EventArgs e) { System.Reflection.Assembly assemblyInfo = System.Reflection.Assembly.GetExecutingAssembly(); Uri uriCodeBase = new Uri(assemblyInfo.CodeBase); string Location = Path.GetDirectoryName(uriCodeBase.LocalPath.ToString()); var path = Location.Split(new string[] { "bin" }, StringSplitOptions.RemoveEmptyEntries); var rootDir = path[0].ToString(); var forPermissionsRootDirectory = Path.GetDirectoryName(rootDir); SetPermissions(forPermissionsRootDirectory); app = this.Application; app.AttachmentContextMenuDisplay += new Outlook.ApplicationEvents_11_AttachmentContextMenuDisplayEventHandler(app_AttachmentContextMenuDisplay);//attach Attachment context Menu Event// } void app_AttachmentContextMenuDisplay(Office.CommandBar CommandBar, Outlook.AttachmentSelection selection) { selectedAttachment = selection; RibbonUI.InvalidateControlMso("ContextMenuAttachments");//will get XML file data// } 

and this is the code in AttachmentContextMenu.cs: -

 public void OnOpenMyMotionCalendarButtonClick(Office.IRibbonControl control) { Outlook.AttachmentSelection selection = ThisAddIn.selectedAttachment; if ((selection.Count > 0)) { //My further working } } 

There is always a null value in the selection for the 2016 forecast. Please suggest what to do?

Regards, Ariel

+6
source share
1 answer

I believe that the Outlook developers added additional logic to free the passed parameter object (attachments). Thus, you need to collect all the necessary information in the event handler, because as soon as the method completes, the object can be destroyed. No one can guarantee that objects remain alive after event handlers have been fired. Do you get a valid object in the AttachmentContextMenuDisplay event handler?

All Outlook add-ins must systematically issue links to Outlook objects when they are no longer needed. Use System.Runtime.InteropServices.Marshal.ReleaseComObject to free an Outlook object when you finish it. Then set the Nothing variable in Visual Basic (null in C #) to free the reference to the object. Read more about this in the article Systematically releasing objects .

0
source

All Articles