Activeator.CreateInstance上的MIME MAPI IConverterSession COMException

时间:2017-01-09 03:24:18

标签: c# outlook mapi

我一直在尝试使用IConverterSession从EML转换为MSG(MIME转换为MAPI),但我一直在绊倒COM错误。 我使用C#MAPIMethods类来包装IConverterSession(就像在这里找到的那​​样:Save Mail in MIME format (*.eml) in Outlook Add-In)。

首先,我遇到了未知clsid的问题,通过这篇文章(https://blogs.msdn.microsoft.com/stephen_griffin/2014/04/21/outlook-2013-click-to-run-and-com-interfaces/)解决了。

现在已经编辑了正确的注册表项,我遇到了一个新问题:首先,我收到一条错误消息The operating system is not presently configured to run this application,我收到一个COMException:Retrieving the COM class factory for component with CLSID {4E3A7680-B77A-11D0-9DA5-00C04FD65685} failed due to the following error: 8007013d The system cannot find message text for message number 0x in the message file for . (Exception from HRESULT: 0x8007013D).

我的代码是:

    Type converter = Type.GetTypeFromCLSID(MAPIMethods.CLSID_IConverterSession, true); 
    object obj = Activator.CreateInstance(converter);
    MAPIMethods.IConverterSession session = (MAPIMethods.IConverterSession)obj;

错误引发于"对象obj = Activator.CreateInstance(转换器);"

COMException通常意味着" type是一个COM对象,但用于获取该类型的类标识符无效,或者标识的类未注册。"。因此,Type converter = Type.GetTypeFromCLSID(MAPIMethods.CLSID_IConverterSession, true);无法返回正确的类型,或者某处仍然缺少注册表项。

我在Win 64bits上使用Office 15(2013)C2R 32位。该应用程序是在x86构建配置上设置的。

我在某处遗失了什么吗?有人可以帮忙吗?

1 个答案:

答案 0 :(得分:1)

“操作系统目前尚未配置为运行此应用程序” - 听起来好像您的应用程序在具有32位版本的Outlook的计算机上编译为x64。

您是否尝试过使用赎回?它为.Net语言包装IConverterSession。像下面这样的事情应该可以胜任。

using Redemption;
...
Redemmption.RDOSession session = new Redemmption.RDOSession();
Redemmption.RDOMail msg = session.CreateMessageFromMsgFile(@"c:\temp\test.msg");
msg.Import(@"c:\temp\test.eml", Redemption.rdoSaveAsType.olRFC822);
msg.Save();

olRFC822格式如果可用,则使用IConverterSession;如果IConverterSesison不可用,则使用内部兑换转换器(例如,在MAPI的Exchange版本或最新版本的Outlook 2016 C2R中无法使用IConverterSession)。 如果您总是想强制使用Redemption或Outlook(IConverterSession)转换器,请使用olRFC822_Redemption或olRFC822_Outlook。