My Windows Forms application uses Outlook Redemption. Recently, I moved some message-listing code into a BackgroundWorker
. On my development machine, it all works fine. However, on a client machine, I get this:
Unable to cast COM object of type 'Redemption.RDOSessionClass' to interface type 'Redemption.IRDOSession'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{E54C5168-AA8C-405F-9C14-A4037302BD9D}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
I found this answer, and the Redemption FAQs, which suggest passing the MAPIOBJECT from the UI thread's RDOSession into the background thread, and using it there on a new RDOSession object.
So I changed the code. In the UI thread (already logged on to the RDOSession):
Me.Bgw.RunWorkerAsync(Email.OlAdmin.Session.MAPIOBJECT)
... and then in the background thread:
Dim sess As New RDOSession
sess.MAPIOBJECT = e.Argument
Dim stores As RDOStores = sess.Stores
...etc
However, with this I get the same error message.
If I change the code back so that it all runs in the foreground, it's fine.
If, however, I actually install Redemption on the client machine (using the installer, which registers the DLL), the background code works fine. This is not an option in production - we ship Redemption with the application and it runs registry-free.
So I'm confused - it appears to be a threading issue (works fine in foreground, fails in background), but passing the MAPIOBJECT to the background worker doesn't help; if I install the DLL, it works fine in background without passing the MAPIOBJECT.
I've also tried completely rebuilding the .NET 3.5 application so that it targets .NET 4.6.2, but it still fails in the same way).
How can I fix it so that it works in the background, but without needing to install Redemption?
Edit: to clarify, in response to Dmitry's question:
- The code above fails on the
sess.MAPIOBJECT = e.Argument
line. - We've never used RedemptionLoader. The EXE includes a manifest containing the Redemption CLSIDs, and the Redemption DLL is included in the application folder.