使用 Redemption RDOContactItem 不能保存超过多个联系人 MAPI_E_TOO_BIG

Using Redemption RDOContactItem cannot save more than a number of contacts MAPI_E_TOO_BIG

发现我正在尝试根据数据库中的值以编程方式(使用 Redemption)在用户邮箱中创建联系人。

RDOContactItem rci = (RDOContactItem)session.GetDefaultFolder(rdoDefaultFolders.olFolderContacts).Folders["Contacts Subfolder"].Items.Add("IPM.Contact");
...
rci.Save();

一达到限制 250,我就收到错误消息:

Error in IMsgStore::OpenEntry(Inbox or Root): MAPI_E_TOO_BIG
ulVersion: 0
Error: Your server administrator has limited the number of items you can open simultaneously. Try closing messages you have opened or removing attachments and images from unsent messages you are composing.
Component: Microsoft Exchange Information Store

阅读 Dmitry Streblechenko 对 http://www.microsoft-questions.com/microsoft/Plaform-SDK-Mapi/32731171/mapietoobig.aspx 的 "This is an indication that you have too many open objects. Do you open each and every message in a folder?" 建议的评论,甚至尝试了他的建议 "Do you release all Exchange objects as soon as you are done with them?"

if (rci != null) Marshal.ReleaseComObject(rci);

甚至转换为 IDisposable 以能够处理它,但它没有用。

保存后找不到关闭联系人的方法。

增加服务器端可同时打开的项目数也不是一个令人满意的选择。

如何解决?

您正在使用多点表示法(如果我没数错的话是 5),这会导致编译器创建您无法显式释放的隐式变量。尝试以下操作。您也可以尝试每隔一段时间调用 GC.Collect(),但这将是一个解决方案的大锤...

RDOFolder contacts = session.GetDefaultFolder(rdoDefaultFolders.olFolderContacts);
RDOFolders folders = contacts.Folders;
RDOFolder subfolder = folders["Contacts Subfolder"];
RDOItems items = subfolder.Items;
RDOMail msg = items.Add("IPM.Contact");
RDOContactItem rci = (RDOContactItem)msg;
...
rci.Save();
Marshal.ReleaseComObject(rci);
Marshal.ReleaseComObject(msg);
Marshal.ReleaseComObject(items);
Marshal.ReleaseComObject(subfolder);
Marshal.ReleaseComObject(folders);
Marshal.ReleaseComObject(contacts);