Strange behaviour of "Call was rejected by callee." exception with Excel

0

I have an application that includes data exporting to Excel. And it works fine on most computers. However, there're two that throw

Call was rejected by callee. (Exception from HRESULT: 0x80010001 (RPC_E_CALL_REJECTED))

when I try to open Worksheet with get_item(). The funny thing is, when I set up breakpoints and execute everything string by string there are no exceptions whatsoever. Everything works fine and smooth. But in normal working behaviour, it just gives this exception.

MyApp = new Excel.Application();
MyApp.Visible = false;
string FileFullPath = Path.GetFullPath("Resources/Excel/FullMonthlyAct.xls");
MyBook = MyApp.Workbooks.Open(FileFullPath);
MySheet = (Excel.Worksheet)MyBook.Worksheets.get_Item(1); 
Excel.Range excelCell = MySheet.Cells[1, 1] as Excel.Range;

UPDATE: It's not a duplicate of the mentioned questions. There, most of the answers tell to check Office activation/installation/file assosiation. And as I've found out with the help of Hans Passant, i get this error simply because Excel can't load the workbook in time.

UPDATE: Solved Not the most elegant solution maybe, but it's possible to just wait till Excel opens the workbook as described in https://stackoverflow.com/a/54126361/1442373 by Joost.

c#
excel
excel-interop
asked on Stack Overflow Dec 26, 2018 by Tumist • edited Jan 24, 2019 by Tumist

1 Answer

-1

Your applicaton will work on all machines that have excel installed and properly activated. It is not working on those machines because they might not have activated microsoft excel properly. You need to make sure it and the problem will be resolved.

answered on Stack Overflow Dec 26, 2018 by Nikunj • edited Dec 26, 2018 by Lewis86

User contributions licensed under CC BY-SA 3.0