I am maintaining a service written to synchronize Contacts with EWS (ExchangeWebService).
This service is updating contactpictures which stopped working recently.
The exception thrown is a DeleteAttachmentException
Initially the code looked like this:
contact.SetContactPicture(filePath);
contact.Update(ConflictResolutionMode.AlwaysOverwrite); // throws the excpetion
Eventhough it only "overwrites" the contactpicture, it seems the old one gets deleted first internally, hence the error message i guess.
So i tried to manually make sure of the deletion first,
which is not a soloution either:
if(contact.HasPicture)
{
contact.RemoveContactPicture();
contact.Update(ConflictResolutionMode.AlwaysOverwrite); // throws the Exception
}
When creating new contacts, this works fine. It displays the Contactpicture. However the updating of existing ones doesnt work.
Sadly the Exception doesnt provide much information:
Microsoft.Exchange.WebServices.Data.DeleteAttachmentException ist aufgetreten.
_HResult=-2146233088
_message=At least one attachment couldn't be deleted.
HResult=-2146233088
IsTransient=false
Message=At least one attachment couldn't be deleted.
Source=Microsoft.Exchange.WebServices
StackTrace:
Microsoft.Exchange.WebServices.Data.AttachmentCollection.InternalDeleteAttachments(IEnumerable`1 attachments)
InnerException:
The whole thing runs in usercontext (owner of the mailbox).
UPDATE
I made it completely independet whether the Attachment is a ContactPicture or whatever, still same result:
_item is an ExchangeItem (which has been loaded)
public void UpdateAttachment(string attachmentPath, string attachmentName)
{
Attachment attachment = _item.Attachments.SingleOrDefault(att => String.Equals(att.Name, attachmentName, StringComparison.OrdinalCultureIgnoreCase));
if (attachment != null)
{
_item.Attachments.Remove(attachment);
_item.Update(ConflictResolutionMode.AlwaysOverwrite);
}
attachment = _item.Attachments.AddFileAttachment(attachmentName, attachmentPath);
_item.Update(ConflictResolutionMode.AlwaysOverwrite);
}