Strange behaviour of “Call was rejected by callee.” exception with Excel [duplicate]

浪尽此生 提交于 2020-01-06 11:49:43

问题


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.


回答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.



来源:https://stackoverflow.com/questions/53931234/strange-behaviour-of-call-was-rejected-by-callee-exception-with-excel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!