5

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?

Ondrej Janacek
  • 12,486
  • 14
  • 59
  • 93
Niklas
  • 23,674
  • 33
  • 131
  • 170
  • 2
    Try to read the following: http://support.microsoft.com/kb/870655 – Dor Cohen Feb 11 '13 at 09:35
  • I am still getting the same error. Should I reboot after I have changed the registry key? – Niklas Feb 11 '13 at 09:42
  • I can create now a new Outlook Application, if a Outlook Instance isn't running. I started Visual Studio without admin rights. – Niklas Feb 11 '13 at 13:02
  • Yes I can create a Outlook instance now, maybe it was the registry key which affected the exception. – Niklas Feb 11 '13 at 13:13

3 Answers3

7

It is because of privileges of the process.Please run Visual studio and outlook as administrator.

Simple solution. Run both as administrator or run both as normal privilege level.

Regards Rameez Ali

RameezAli
  • 956
  • 11
  • 12
5

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

Dor Cohen
  • 16,769
  • 23
  • 93
  • 161
  • 1
    Very helpful answer. Could you add the relevant change to the registry key in case the link breaks? – fuchs777 May 02 '16 at 07:34
  • I had a related situation. I confirm that running visual studio (or the app) AND outlook with the same permission model (both admin or both normal) fixes this problem. However I have not tested the workaround in the registry. (Tested with Outlook 2016) – juFo Oct 25 '16 at 06:57
  • The article says to add 512 but my has set 768: `ObjectDirectory=\Windows SharedSection=1024,20480,768`. And I have noticed that the ServerDll is set as sxssrv: `ServerDll=sxssrv`. I presume that is the default configuration in registry since I did not change it. I am wondering what is 512 anyway? – Junior Mayhé Mar 21 '17 at 12:27
0

Following Steps may be helpful...

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\SubSystems - Windows

%SystemRoot%\system32\csrss.exe ObjectDirectory=\Windows SharedSection=1024,3072,512 Windows=On SubSystemType=Windows ServerDll=basesrv,1 ServerDll=winsrv:UserServerDllInitialization,3 ServerDll=winsrv:ConServerDllInitialization,2 ProfileControl=Off MaxRequestThreads=16

ASP.net user must be excist on Admin Tools/Computer Management/User


For 32-bit (x86), create this folder: C:\Windows\System32\config\systemprofile\Desktop--> add Network Services

Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files give write permissions.

in Web.config change impersonate= true,

in IIS for windows server 2003 select the account as NETWORK SERVICE.

In DCOMCONFIG change identity as The interactive User.

Also for the particular directory give all the rights.


Internet Options - Advanced tab. Scroll all the way to the bottom and uncheck item called "Check for Publisher's certificate revocation."

Registry: CLSID: {0006F03A-0000-0000-C000-000000000046} Under this key in HKEY_CLASSES_ROOT\CLSID\, add a string value AppID = same value as the IDs Eg:{0006F03A-0000-0000-C000-000000000046}

Then under HKEY_CLASSES_ROOT\AppID\ add a string value: RunAs = Interactive User

Right click on CLSID & APPID, Permission, Security, and edit both the launch & access permissions to add and give Network Service and Interactive full permissions.


Disable all other Outlook add-ins: Outlook Tools menu | Options | Other tab | Advanced Options | COM Add-Ins | uncheck the items. If this solves the problem, then re-enable one add-in at a time until the problem reappears


give read/write access to IIS user for folder "C:\WINDOWS\TEMP" All Dll should be placed on C:\Program Files\Microsoft Visual Studio 9.0\Visual Studio Tools for Office\PIA\Office12

Raj
  • 800
  • 7
  • 8