Tuesday, March 20, 2012

VB.NET - Office (Word, Excel...) - RPC Server Error

In my application I would seem to randomly get errors that would say something like:


  • The server threw an exception. (Exception from HRESULT ... (RPC_E_SERVERFAULT))
  • The RPC server is unavailable. (Exception from HRESULT ...)

I could not discover the root of the problem nor a solution. I found out this issue is typically caused by Microsoft Word (or whichever Office application) not closing correctly. If you interrupt it while running a process and then try to open a specific file again an error may occur.  Furthermore this happens when you open multiple instances of Word opening, closing, and running at the same time.  The instances of Word will attempt to "piggyback" off one another. When one instance closes but another attempts to run a process, the error is generated.

To solve this issue at the root of the problem you will need to make sure you are instantiating instances of word that are isolated from each other.

If you have done this, another possible source of the error is that you need to enable a template or document that was disabled.

To correct this you need to enable the file that is causing the problem because it has become disabled.  Open Microsoft Word (or other Office application), click the office button, click "Word Options". Then under "Add-Ins", click the "Manage" dropdown list and select "Disabled Items". Click "go". Select any items that are disabled and then click "Enable".

Try running your application again and it should work now.

If not, the RPC error is being caused by something else now.

No comments:

Post a Comment