Error "The operation can not be performed Because the message Has Been changed"

Being of the email changes saved, then the execution of the mail Save () method, you may experience the error "The operation can not be performed Because the message Has Been changed." Especially if you go to edit multiple email.

This is due to the object Microsoft.Office.Interop.Outlook.UserProperty that was not released. So before the save is to be performed education System.Runtime.InteropServices.Marshal.ReleaseComObject (UserProperty).
At this stage the previous post snippet becomes 
public void AddCustomPropertyToMail (entryID string, string propertyName, string value) 
{ 
 Microsoft.Office.Interop.Outlook.MailItem mail = Globals.ThisAddIn.Application.Session.GetItemFromID (entryID) as Microsoft.Office.Interop.Outlook.MailItem; 
 if (email! = Null) 
 { 
  Microsoft.Office.Interop.Outlook.UserProperty UserProperty = mail.UserProperties.Add (propertyName, Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText); 
  UserProperty.Value = value; 
  System.Runtime.InteropServices.Marshal.ReleaseComObject (UserProperty); // IMPORTANT: you must release the object properties otherwise Save goes into error "The operation can not be performed Because the message Has Been changed." 
  mail.Save (); 
  System.Runtime.InteropServices.Marshal.ReleaseComObject (mail); 
  Mail = null; 
 } 
} 

Comments

Popular posts from this blog

C# Crop white space from around the image

Could not load file or assembly 'Microsoft.ReportViewer.Common, Version=xx.0.0.0, Culture=neutral, PublicKeyToken='xxx' or one of its dependencies.

The specified version string contains wildcards, which are not compatible with determinism.