Outlook Interop exception - displaying new mailitem

守給你的承諾、 提交于 2019-12-13 06:13:03

问题


Trying to automatically generate a mail message via Outlook -

Added a reference to Microsoft.Office.Interop.Outlook 14.0.0.0

It works on a Win 8/Office 2013 PC, but fails with the following exception on Win 7/Office 2010.

Code:

Application outlookApp = new Application();
MailItem message = (MailItem)outlookApp.CreateItem(OlItemType.olMailItem);
message.Subject = "subject";
message.Display(message);
message.HTMLBody = "body" + message.HTMLBody; //to get default signature

The exception is:

Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Office.Interop.Outlook.Application'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{00063001-0000-0000-C000-000000000046}' failed due to the following error: Library not registered. (Exception from HRESULT: 0x8002801D (TYPE_E_LIBNOTREGISTERED)).


回答1:


Solution ended up being:

http://www.fieldstonsoftware.com/support/support_gsyncit_2013.shtml

Lync 2013 was installed on top of Office 2010. This adds a registry entry to HKCR\TypeLib{00062FFF-0000-0000-C000-000000000046}.

Subkey to that registry entry will be different numbered folders, indicating version numbers of Office installed. (9.4 in this case, indicates 2010, 9.5 indicates 2013). Once the version number not consistent with the version of Outlook was deleted, it was resolved.



来源:https://stackoverflow.com/questions/17810163/outlook-interop-exception-displaying-new-mailitem

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!