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
- Microsoft.Office.Core
- VBIDE
- Word
If you do not see these added, make sure you have PIAs for office version installed on your machine.
Get Office 2007 PIAs here
Get Office 2003 PIAs here
Related Posts
- C# Word Automation: Inserting Images
- C# Word Automation : How to add a Shape textbox
- C# Word Automation: Inserting images with text wrapping around
Categories: .NET

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…
Close and destroy your data structures properly and you will not need this event or see this error message