Activator.CreateInstance 上的 MIME MAPI IConverterSession COMException
MIME MAPI IConverterSession COMException on Activator.CreateInstance
我一直在尝试使用 IConverterSession 将 EML 转换为 MSG(MIME 到 MAPI),但我一直遇到 COM 错误。
我使用 C# MAPIMethods class 来包装 IConverterSession(就像在此处找到的那样:Save Mail in MIME format (*.eml) in Outlook Add-In)。
首先,我遇到了未知 clsid 的问题,用这个 post (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;
错误发生在 "object obj = Activator.CreateInstance(converter);"
COMException 通常意味着 "type is a COM object but the class identifier used to obtain the type is invalid, or the identified class is not registered."。所以要么 Type converter = Type.GetTypeFromCLSID(MAPIMethods.CLSID_IConverterSession, true);
没有 return 正确的类型,要么某处仍然缺少注册表项。
我在 Win 64 位上使用 Office 15 (2013) C2R 32 位。该应用程序是在 x86 构建配置上设置的。
有什么我遗漏的地方吗?有人可以帮忙吗?
"The operating system is not presently configured to run this application" - 听起来您的应用确实在装有 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
不可用)(例如,在 Exchange 版本的 MAPI 或最新版本的 Outlook 2016 下无法使用 IConverterSession 的 C2R)。
如果您总是想强制使用 Redemption 或 Outlook (IConverterSession) 转换器,请使用 olRFC822_Redemption 或 olRFC822_Outlook。
我一直在尝试使用 IConverterSession 将 EML 转换为 MSG(MIME 到 MAPI),但我一直遇到 COM 错误。 我使用 C# MAPIMethods class 来包装 IConverterSession(就像在此处找到的那样:Save Mail in MIME format (*.eml) in Outlook Add-In)。
首先,我遇到了未知 clsid 的问题,用这个 post (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;
错误发生在 "object obj = Activator.CreateInstance(converter);"
COMException 通常意味着 "type is a COM object but the class identifier used to obtain the type is invalid, or the identified class is not registered."。所以要么 Type converter = Type.GetTypeFromCLSID(MAPIMethods.CLSID_IConverterSession, true);
没有 return 正确的类型,要么某处仍然缺少注册表项。
我在 Win 64 位上使用 Office 15 (2013) C2R 32 位。该应用程序是在 x86 构建配置上设置的。
有什么我遗漏的地方吗?有人可以帮忙吗?
"The operating system is not presently configured to run this application" - 听起来您的应用确实在装有 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
不可用)(例如,在 Exchange 版本的 MAPI 或最新版本的 Outlook 2016 下无法使用 IConverterSession 的 C2R)。
如果您总是想强制使用 Redemption 或 Outlook (IConverterSession) 转换器,请使用 olRFC822_Redemption 或 olRFC822_Outlook。