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

62 Views Asked by At

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.

2

There are 2 best solutions below

0
Dmitry Streblechenko On BEST ANSWER

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.

7
Eugene Astafiev On

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)

Sounds like the Redemption library is trying to take a screenshot when the handle is invalid. This is a possible scenario when running the code under unattended scenario. See Taking screenshot not working in window service c# for more information.