Excel Interop Workbooks.Open inconsistencies

1

I have a process that is opening multiple workbooks

var exApp = new Excel.Application(); 
Excel.Workbook ONE;
Excel.Workbook TWO;
Excel.Workbook THREE;
ONE = exApp.Workbooks.Open(ONELocation);
TWO = exApp.Workbooks.Open(TWOLocation);
THREE = exApp.Workbooks.Open(THREELocation);
Console.WriteLine("All Excel workbooks opened successfully\n");

Sometimes it runs with no issues.

Sometimes though I get the following exception on crash

System.Runtime.InteropServices.COMException: 'The remote procedure call failed. (Exception from HRESULT: 0x800706BE)'

The exception happens on different workbooks and sometimes not at all. When it happens after rerunning a few times the process goes through successfully and all data is processed correctly.

Why does it work sometimes and not others? Is there a better way to open these workbooks? How do I stop this from happening?

c#
excel
excel-interop
asked on Stack Overflow Jun 19, 2017 by hellyale • edited Jun 19, 2017 by hellyale

1 Answer

1

RPC_S_CALL_FAILED was indeed the root cause as pointed out by the question user xxbbcc linked to as a possible duplicate.

However, that just told me the cause and did not solve the problem. I googled RPC_S_CALL_FAILED with the word excel and found this SuperUser question

I disabled the "FoxitReader PDF Creator COM Add-in" as described in the question and my program now runs consistently without error.

How to disable the plugin: Excel > File > Options > Add-ins > Manage, then choose "COM add-ins" > Go. And then untick the problematic plugin.

answered on Stack Overflow Jun 19, 2017 by hellyale

User contributions licensed under CC BY-SA 3.0