Excel threw "The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)" exception RRS feed

  • Question

  • Hi,

    I have a excel VSTO add-in which is used for reporting, i have another process which opens an excel instance in the background loads the add-in and manipulate the data in excel, it will then save the excel and release the com objects for workbook and excel application using System.Runtime.InteropServices.Marshal.ReleaseComObject

    Usually it runs smoothly without any issue but today i got the following error, while loading the add-in :

    Exception Message : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)

    Exception Stack Trace :    at Microsoft.Office.Core.COMAddIn.get_Connect()
       at myapp.Async.Refresh.Core.myAddIn..ctor(COMAddIn comAddIn)
       at myapp.Async.Refresh.Core.RenderingAsyncService.OpenExcel(String reportLocation, Application& xlApp, Workbook& xlWorkBook)

    The following code snippet is used as a part of loading the add-in and from where the exception arised:

    Exception ex = null;
    Stopwatch tmrAddinConnect = new Stopwatch();
    ex = null;
    if (!comAddIn.Connect) comAddIn.Connect = true;
    catch (Exception e) { ex = e; }
    while (!comAddIn.Connect && (tmrAddinConnect.Elapsed.TotalSeconds) < 8); // Give up after 8 seconds
    if (!comAddIn.Connect && ex != null) throw ex;

    So i wanted to understand the reason behind this exception and  what may be done to avoid it in future.



    Wednesday, January 22, 2020 5:53 AM

All replies

  • Hello Abhijit,


    Do you run multiple threads in the application? Where and when do you create an instance of the Excel application?

    i have another process which opens an excel instance in the background loads the add-in and manipulate the data in excel

    Is it a windows service? Where do you run this application?

    Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

    If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution.

    Read more about that in the Considerations for server-side Automation of Office article. 

    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    Thursday, January 23, 2020 7:21 AM