1

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.

Tumist
  • 119
  • 3
  • 11
  • 1
    It is the error you'll get back from Excel when you slam it with too much work to do. Running this code in a worker thread is a typical reason. So sure, slowing it down with a debugger or running it on a fast machine are ways to avoid it. That is one gawdawful horribly miserable duplicate, google "office imessagefilter" to find the code you need to tell it to keep waiting. – Hans Passant Dec 26 '18 at 14:06
  • 1
    I confirm that this is NOT a duplicate question. I had the error 1 times out of 3, running the same script on the same machine. Once I did put a 5-second wait after the workbook.Open command, it worked all the time. – Joost Jan 10 '19 at 10:09
  • Check my response to the other question (including a code sample to wait for Excel to be ready before continuing): https://stackoverflow.com/a/54126361/1442373 – Joost Jan 10 '19 at 10:18

1 Answers1

0

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.

Lewis86
  • 511
  • 6
  • 15
Nikunj
  • 195
  • 10