I have a VSTO add-in, that looks up an Outlook task by an EntryID or a Subject, and does some operations on it.
One of the users logged the following error message from it:
Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE))
Here's the function that finds the Task Item
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;
}
I've found a couple of explanations for the error log, but none of them really made sense (multiple users accessing the same COM interface, messed up registry etc.)
Any clear signs that maybe the code is wrong, and that's the reason this exception is being generated, or it's Outlooks fault?
I have to mention, that I'm instantiating Outlook from another Office application.
This most likely means your app is running in a security context different from that of Outlook.
Is either app running with elevated privileges (Run as Administrator)?
Also, if this code is in an addin, why are you creating a new instance of the Outlook.Application instead of using the instance passed to your addin?
User contributions licensed under CC BY-SA 3.0