Home

Error occurring randomly when performing Office 365 automation with Microsoft.Office.Interop library

%3CLINGO-SUB%20id%3D%22lingo-sub-1127596%22%20slang%3D%22en-US%22%3EError%20occurring%20randomly%20when%20performing%20Office%20365%20automation%20with%20Microsoft.Office.Interop%20library%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1127596%22%20slang%3D%22en-US%22%3E%3CP%3EWe%20are%20experiencing%20a%20strange%20behavior%20these%20past%20days%20with%20Excel%20server%20automation%20using%20Microsoft.Office.Interop.Excel%2C%20Version%3D15.0.0.0%20library.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20problem%20happened%20on%20Office%20365%20and%20it%20is%20random%20on%20the%20same%20file%20(sometimes%20it%20works%20sometimes%20it%20is%20not).%20The%20application%20was%20working%20properly%20for%20years%20without%20any%20king%20of%20issue.%20The%20first%20time%20we%20experienced%20this%20issue%20was%20on%3CBR%20%2F%3E14th%20January%202020%20and%20by%20searching%20online%20we%20found%20out%20that%20this%20coincide%20with%20the%20date%20of%20the%20security%20update%20as%20indicated%20in%20this%20Microsoft%20page%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fofficeupdates%2Foffice365-proplus-security-updates%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fofficeupdates%2Foffice365-proplus-security-updates%3C%2FA%3E.%20Any%20idea%20how%20to%20solve%20this%20issue%3F%20We%20tried%20to%20analyse%20Application%20Event%20Viewer%20to%20see%20if%20there%20is%20more%20details%20about%20the%20issue%20but%20no%20meaningful%20detail%20was%20found.%20The%20problem%20randomly%20occurs%20on%20these%20lines%20of%20code%3A%3C%2FP%3E%3CP%3E%3CBR%20%2F%3E%3CFONT%20color%3D%22%23008000%22%3E%3CEM%3EApplication%20excelApp%20%3D%20new%20Application()%3B%3C%2FEM%3E%3C%2FFONT%3E%3CBR%20%2F%3Eor%20later%20when%20we%20open%20workbook%20with%20following%20line%20of%20code%3A%3CBR%20%2F%3E%3CFONT%20color%3D%22%23008000%22%3E%3CEM%3EexcelApp.Workbooks.Open(fileName%2C%20true%2C%20true)%3B%3C%2FEM%3E%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20is%20the%20exception%20we%20get%20when%20the%20process%20failed%20on%20opening%20workbook%3A%3C%2FP%3E%3CP%3E%3CFONT%20color%3D%22%23FF0000%22%3EThe%20remote%20procedure%20call%20failed.%20(Exception%20from%20HRESULT%3A%200x800706BE)%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20color%3D%22%23FF0000%22%3ESystem.Runtime.InteropServices.COMException%20(0x800706BE)%3A%20The%20remote%20procedure%20call%20failed.%20(Exception%20from%20HRESULT%3A%200x800706BE)%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20color%3D%22%23FF0000%22%3Eat%20Microsoft.Office.Interop.Excel.Workbooks.Open(String%20Filename%2C%20Object%20UpdateLinks%2C%20Object%20ReadOnly%2C%20Object%20Format%2C%20Object%20Password%2C%20Object%20WriteResPassword%2C%20Object%20IgnoreReadOnlyRecommended%2C%20Object%20Origin%2C%20Object%20Delimiter%2C%20Object%20Editable%2C%20Object%20Notify%2C%20Object%20Converter%2C%20Object%20AddToMru%2C%20Object%20Local%2C%20Object%20CorruptLoad)%3C%2FFONT%3E%3CBR%20%2F%3E%3CFONT%20color%3D%22%23FF0000%22%3Eat%20GeneratorEngine.ExcelAddinGenerator.InitializeWorkBook(Int32%26amp%3B%20winProcessId)%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CBR%20%2F%3EThank%20you%20for%20your%20precious%20help.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1127596%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EOffice%20365%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Highlighted
alinoson
Occasional Visitor

We are experiencing a strange behavior these past days with Excel server automation using Microsoft.Office.Interop.Excel, Version=15.0.0.0 library.

 

The problem happened on Office 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://docs.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 these lines of code:


Application excelApp = new Application();
or later when we open workbook with following line of code:
excelApp.Workbooks.Open(fileName, true, true);

 

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)
at GeneratorEngine.ExcelAddinGenerator.InitializeWorkBook(Int32& winProcessId)


Thank you for your precious help.