Outlook互操作代码会抛出“邮件已更改".代码第二次尝试保存邮件项目时发生错误 [英] Outlook interop code throws "message has been changed" error the second time when the code tries to save a mail item

查看:192
本文介绍了Outlook互操作代码会抛出“邮件已更改".代码第二次尝试保存邮件项目时发生错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,此问题仅在少数客户端计算机上发生,而我无法在任何测试计算机上复制它.

First of all, this problem only happens on a few client machines and I can not replicate it on any of my test machines.

所以我在LINQPad中有以下测试代码:

So I have the following test code in LINQPad:

var application = new Application();
var session = application.Session;
const string entryId = "arbitrary entry ID";
const string propertyName = "http://schemas.microsoft.com/mapi/string/{31A9B8DA-D4A0-4B96-87AE-01D6E9BCFCCE}/Test/0x0000001F";

// Save test property for the first time.
var mail = (MailItem)session.GetItemFromID(entryId);
var propertyAccessor = mail.PropertyAccessor;
propertyAccessor.SetProperty(propertyName, 1);
mail.Save();

Marshal.ReleaseComObject(propertyAccessor);
Marshal.ReleaseComObject(mail);

// Save test property for the second time.
mail = (MailItem)session.GetItemFromID(entryId);
var propertyAccessor = mail.PropertyAccessor;
propertyAccessor.SetProperty(propertyName, 2);
mail.Save();

Marshal.ReleaseComObject(propertyAccessor);
Marshal.ReleaseComObject(mail);
Marshal.ReleaseComObject(session);
Marshal.ReleaseComObject(application);

在这几台客户端计算机上,第二个mail.Save()调用的速率为100%,引发异常:System.Runtime.InteropServices.COMException (0x80040109): The operation cannot be performed because the message has been changed.

The second mail.Save() call has a 100% rate on these few client machines to throw the exception: System.Runtime.InteropServices.COMException (0x80040109): The operation cannot be performed because the message has been changed.

由于上述代码正确释放了第一个mail对象,并再次使用条目ID检索了第二个mail对象.在第二次检索对象和调用其Save()方法之间更改mail对象的机会非常低,更不用说100%的可重复率了.

Since the above code properly releases the first mail object and retrieves the second mail object using entry ID again. The chance to have something changing the mail object between the second retrieval of the object and calling its Save() method is very low, not to mention the 100% reproducible rate.

我只能认为它看起来像Outlook中的错误,一旦有人调用Save()方法,它就可能永久将邮件对象标记为已更改.

I can only think that it looks like a bug in Outlook that it may permanently mark a mail object as changed as soon as anything calls the Save() method once.

有人知道是否有解决方法吗?

Does any one know if there is a work around?

这些计算机正在使用最新版本的Office 2016.

These machines are using the latest version of Office 2016.

推荐答案

IMAP4是最糟糕的问题之一-每当您尝试触摸任何存储对象时,它都会尝试进行同步.您可以尝试绕过IMAP4层,然后直接转到用作基础本地存储的PST提供程序.在扩展MAPI(C ++或Delphi)中,您可以使用兑换及其商店.UnwrapStore方法-然后可以使用 RDOStore .GetMessageFromID.

IMAP4 is one of the worst - every time you try to touch any of the store objects, it tries to sync. You can try to bypass the IMAP4 layer and go directly to the PST provider used as the underlying local storage. In Extended MAPI (C++ or Delphi), you can do that using the IProxyStoreObject interface. In case of languages other than C++ or Delp you can use Redemption and its RDOSession.Stores.UnwrapStore method - the message can be then opened from the unwrapped store using RDOStore.GetMessageFromID.

这篇关于Outlook互操作代码会抛出“邮件已更改".代码第二次尝试保存邮件项目时发生错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆