I am experiencing a strange behavior these past days with Excel server automation using Microsoft.Office.Interop.Excel library.
The problem happened with different versions of Excel(2016, 2019, 365) and it is random on the same file (sometimes it works sometimes it is not). The application was working properly for years without any king of issue. The first time we experienced this issue was on 14th January 2020 and by searching online we found out that this coincide with the date of the security update as indicated in this Microsoft page https://learn.microsoft.com/en-us/officeupdates/office365-proplus-security-updates. Any idea how to solve this issue? We tried to analyse Application Event Viewer to see if there is more details about the issue but no meaningful detail was found. The problem randomly occurs on 'Workbooks.Open':
...
string filePath = @"C:\ExcelFiles\Test.xlsx";
Application excelApp = new Application();
excelApp.Workbooks.Open(filePath , true, true);
...
The issue has been observed on Microsoft Windows Server 2016 and Microsoft Windows Server 2019. I also noticed that the problem always happened when i opened Remote Desktop on the server but when i logged off the server the excel automation then start working properly again. I have no idea how the RDP can conflict with excel automation.
This is the exception we get when the process failed on opening workbook:
The remote procedure call failed. (Exception from HRESULT: 0x800706BE) System.Runtime.InteropServices.COMException (0x800706BE): The remote procedure call failed. (Exception from HRESULT: 0x800706BE) at Microsoft.Office.Interop.Excel.Workbooks.Open(String Filename, Object UpdateLinks, Object ReadOnly, Object Format, Object Password, Object WriteResPassword, Object IgnoreReadOnlyRecommended, Object Origin, Object Delimiter, Object Editable, Object Notify, Object Converter, Object AddToMru, Object Local, Object CorruptLoad)
Thank you for your precious help.