Getting COMException when accessing Emails on Outlook 2010

♀尐吖头ヾ 提交于 2020-01-23 07:33:30

问题


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?


回答1:


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




回答2:


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




回答3:


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



来源:https://stackoverflow.com/questions/14809242/getting-comexception-when-accessing-emails-on-outlook-2010

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!