4

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.
ChrisA
  • 4,163
  • 5
  • 28
  • 44
  • Do you get that error on the "new" lien or when setting the MAPIOBJECT property? Are you using the latest RedemptionLoader? – Dmitry Streblechenko Aug 03 '17 at 22:02
  • @DmitryStreblechenko: thanks for responding - please see the edit above. – ChrisA Aug 04 '17 at 12:47
  • Have you tried what I described in my answer here: https://stackoverflow.com/questions/4685237/how-can-i-make-a-background-worker-thread-set-to-single-thread-apartment – Simon Mourier Aug 10 '17 at 04:44
  • @SimonMourier - no I haven't, thanks for the heads up. I'll give it a go. – ChrisA Aug 10 '17 at 07:39
  • @SimonMourier I've now tried the overridden SynchronizationContext method in your answer, but it doesn't change the ApartmentState of the BGW thread. In fact, it doesn't go through the Post code until the BG thread finishes. I'll update the question to explain what I've done - hopefully you'll be able to spot where I'm going wrong. – ChrisA Aug 12 '17 at 09:40
  • https://stackoverflow.com/a/19815060/17034 – Hans Passant Sep 05 '17 at 16:20

0 Answers0