我有一个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接口,搞砸了注册表等。)
任何明显的迹象表明代码可能是错误的,这是导致生成此异常的原因,还是Outlook的错误?
我必须提一下,我是从另一个Office应用程序实例化Outlook。
答案 0 :(得分:0)
这很可能意味着您的应用程序在与Outlook不同的安全上下文中运行 应用程序是否以提升的权限运行(以管理员身份运行)?
此外,如果此代码在插件中,为什么要创建Outlook.Application的新实例而不是使用传递给插件的实例?