Search code examples
c#outlooknunitoutlook-addinoutlook-redemption

Outlook Redemption Error: System.ComponentModel.Win32Exception: The handle is invalid


I have test suit for outlook MAPI created in C#, which uses Redemption.

Which executing below try{} catch{} block it is throwing below exception. Any idea what needs to be done?

try
{
    _RDOSession = new Redemption.RDOSessionClass();
    _RDOSession.MAPIOBJECT = OutlookConnection.Instance.nameSpace.MAPIOBJECT;
    _MAPIUtils = new MAPIUtils();
}
catch (System.Exception e)
{
    throw new HarnessException("OutlookRedemption threw exception for _RDOSession", e);
}

.
.
.
.

try
{
    _OutlookApplication = new Microsoft.Office.Interop.Outlook.ApplicationClass();
}
catch (System.Exception e)
{
    throw new HarnessException("OutlookConnection threw exception for _OutlookApplication", e);
}

It shows below errors in order:

OutlookConnection threw exception for _OutlookApplication SyncHarness.HarnessException: OutlookConnection threw exception for _OutlookApplication ---> System.Runtime.InteropServices.COMException (0x80080005): Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80080005. at SyncHarness.OutlookConnection..ctor()

OutlookRedemption threw exception for _RDOSession SyncHarness.HarnessException: OutlookRedemption threw exception for _RDOSession ---> System.ComponentModel.Win32Exception: The handle is invalid at System.Drawing.Graphics.CopyFromScreen(Int32 sourceX, Int32 sourceY, Int32 destinationX, Int32 destinationY, Size blockRegionSize, CopyPixelOperation copyPixelOperation)

Tried modifying registry according to https://learn.microsoft.com/en-us/troubleshoot/windows-server/application-management/error-8008005-when-start-complus-applications

But didn't help.


Solution

  • 0x80080005 is CO_E_SERVER_EXEC_FAILURE, most likely this happens if the security context of your app and Outlook are different. if either app is running with elevated privileges (Run As Administrator), make sure that either both do, or none.