【发布时间】:2017-10-19 17:55:59
【问题描述】:
我有一个 VSTO 加载项,它通过 EntryID 或 Subject 查找 Outlook 任务,并对其执行一些操作。
其中一位用户从中记录了以下错误消息:
由于以下错误,检索具有 CLSID {0006F03A-0000-0000-C000-000000000046} 的组件的 COM 类工厂失败:80080005 服务器执行失败(来自 HRESULT 的异常:0x80080005 (CO_E_SERVER_EXEC_FAILURE))
这是查找任务项的函数
public Outlook.TaskItem FindTask(String EntryID, String Subject)
{
try
{
Outlook.Application OutlookApp = new Outlook.Application();
Outlook.NameSpace ns = null;
Outlook.MAPIFolder tasksFolder = null;
Outlook.Items taskFolderItems = null;
Outlook.Items filteredtaskFolderItems = null;
Outlook.TaskItem task = null;
ns = OutlookApp.Session;
ns.SendAndReceive(false);
tasksFolder = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderTasks);
taskFolderItems = tasksFolder.Items;
//Try to find the task by entryID
dynamic OutlookItem = null;
OutlookItem = ns.GetItemFromID(EntryID);
if (OutlookItem != null)
{
if (OutlookItem is Outlook.TaskItem)
{
Outlook.TaskItem foundItem = (Outlook.TaskItem)OutlookItem;
return foundItem;
}
}
//If not found by EntryID, find it by a Subject
string subjectmatch = "[Subject] ='" + Subject + "'";
filteredtaskFolderItems = taskFolderItems.Restrict(subjectmatch);
for (int i = 1; i <= filteredtaskFolderItems.Count; i++)
{
task = (Microsoft.Office.Interop.Outlook.TaskItem)filteredtaskFolderItems[i];
return task;
}
}
catch(Exception ex)
{
//log exception
}
return null;
}
我找到了一些关于错误日志的解释,但没有一个真正有意义(多个用户访问同一个 COM 接口、注册表混乱等)
有任何明显迹象表明代码可能是错误的,这就是生成此异常的原因,还是 Outlooks 错误?
我必须提到,我正在从另一个 Office 应用程序实例化 Outlook。
【问题讨论】:
标签: outlook vsto outlook-addin office-addins