Search code examples
c#visual-studio-2010emailcomexception

Getting COMException when accessing Emails on Outlook 2010


Hello I am trying to access my emails in Outlook 2010 via a C# Console Application.

Visual Studio is started with admin rights and I have added a reference to Microsoft.Office.Interop.Outlook v14.0.0.0 and used it as Outlook.

My Code:

Console.Write("starting");
Outlook.Application app = new Outlook.Application();
Outlook.NameSpace mapiNameSpace = app.GetNamespace("MAPI");
Outlook.MAPIFolder myInbox = mapiNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
Console.WriteLine(((Outlook.MailItem)myInbox.Items[0]).Subject);
Console.WriteLine("readline:");
Console.ReadLine();

The second line, throws an error message:

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)).

Do you know any solutions?


Solution

  • Try to read the following: http://support.microsoft.com/kb/870655

    Cause:
    If many COM+ applications run under different user accounts that are specified in the This User property, the computer cannot allocate memory to create a new desktop heap for the new user. Therefore, the process cannot start.

    WORKAROUND: To work around this problem, modify the value of the following registry subkey: HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\SubSystems\Windows