Home > .NET > C# Word Automation: Solve “The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)”

C# Word Automation: Solve “The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)”

Assignment:
Export data in word 2003 format using COM Interop

Problem:
First time export worked just fine. Second time, I received exception “The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)” for “Microsoft.Office.Interop.Word”

Solution:

  
public class CDocumentExporter
{
        static ApplicationClass _word_application;

        public static ApplicationClass AppClass
        {
            get
            {

                if (_word_application == null)
                {
                    _word_application = new ApplicationClass();
                    _word_application.ApplicationEvents2_Event_Quit += new ApplicationEvents2_QuitEventHandler(_word_application_ApplicationEvents2_Event_Quit);
                }
                return _word_application;
            }
        }

        static void _word_application_ApplicationEvents2_Event_Quit()
        {
            _word_application = null;
        }
}//end of class

And just use the CDocumentExporter.AppClass wherever necessary

Important information

You need to add a COM reference to your favorite word object library which should in turn add

Related Posts
Categories: .NET
  1. December 8, 2011 at 7:12 am | #1

    You have neither closed the document not did you quit the Word app you opened up… just run 4-5 word files from you app and open up your task bar… you will see several WINWORD processes running…

  2. December 8, 2011 at 7:14 am | #2

    Close and destroy your data structures properly and you will not need this event or see this error message

  1. March 9, 2011 at 9:20 am | #1
  2. March 9, 2011 at 9:23 am | #2
  3. March 9, 2011 at 9:39 am | #3

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 400 other followers