title: DCOM Config settings for Microsoft Interop Word Automation
body: <p>I am using <code>Microsoft Office Interop Word</code> to generate documents using C#. In order for the document generation to work, there should be an entry for the <code>"Microsoft Office Word 97 - 2003 Document"</code> under the <code>Dcom Config Settings</code> as shown below:</p>
  
  <p><img src="https://i.stack.imgur.com/fDrld.jpg" alt="enter image description here"></p>
  
  <p>The <code>Local Path</code> under the <code>General Tab</code> has a correct path when Microsoft Office is first installed. If I then join the computer to a Domain, and then restart the system with a Domain user, the <code>Local Path</code> becomes blank and the application doesn't generate the documents and gives error.</p>
  
  <p>Even if I join the computer to Domain first and then login with Domain user and then install the Microsoft Office, the <code>Local Path</code> appears correct first and then after a restart, it becomes blank again. While, at the same time, if I login with the <code>Local User</code>, the <code>Path</code> is still there.</p>
  
  <p>What is causing the value of <code>Local Path</code> to go blank?</p>
  
  <p>This all setup is on virtual machines and the word automation works on a domain account as I have seen it working on a physical machine joined to domain.</p>
  
  <pre><code>UPDATE: What my application is doing:
  </code></pre>
  
  <p>There are 4-5 components in my application. </p>
  
  <p>The first is a VSTO Word AddIn, which integrates with Microsoft Word, where we create new documents that contain some Expressions that are also saved in the database. There are also conditions on the Expressions and they can be nested also. Expressions contain schema elements from XSD files which are saved in database. Once this type of document is created, its WordML is saved in the database. This all is done in VSTO AddIn.</p>
  
  <p>The second is a Web Service which receives an input xml from another component that confirms to the XSD above from which the schema elements were embedded into the expressions in the document created through VSTO addIn. This web service checks for the validations and several other tasks. It then gets the WordML of the corresponding word document from the database and passes it to the Word Interop which using its APIs, iterates through it recursively to replace the schema elements with their actual values from the input xml. This then saves the WordML to a file as word document.</p>
  
  <p>This also attaches a template to the document before saving it. It uses the SaveAs functionality of Word Interop to also save the file as PDF.</p>
  
  <blockquote>
    <p>UPDATE:
    I have again gone through my complete application and came to know that we are doing all things by parsing the Office Open XML (e.g. for feeding the input to the word document), but the only things that we are doing using Word Automation are following:</p>
  </blockquote>
  
  <ol>
  <li>Using Word Interop to save the generated WordML as one of the Word Format Files.</li>
  <li>Exporting the generated WordML to the PDF file.</li>
  <li>Merging several WordMLs into a single word document file.</li>
  <li>Fetching the XML for it.</li>
  </ol>
  
  <p>All these four codes are shown below with only relevant parts of code:</p>
  
  <pre><code>Microsoft.Office.Interop.Word.Document wordDocument = null;
  object templateName = "templateFile.dotm";
  wordDocument = this.WordApplication.Documents.Add(ref missing, ref missing, ref missing, ref missing);
  wordDocument.Range(ref missing, ref missing).Text = "";
  wordDocument.set_AttachedTemplate(ref templateName);
  
  wordDocument = this.WordApplication.Documents.Open(
                     ref objSourceFilePath, ref oFalse, ref oTrue,
                     ref oMissing, ref oMissing, ref oMissing,
                     ref oMissing, ref oMissing, ref oMissing,
                     ref oMissing, ref oMissing, ref oMissing,
                     ref oMissing, ref oMissing, ref oMissing,
                     ref oMissing);
  wordDocument.ExportAsFixedFormat(
          strTargetPath,
          targetFormat,
          paramOpenAfterExport,
          paramExportOptimizeFor,
          paramExportRange,
          paramStartPage,
          paramEndPage,
          paramExportItem,
          paramIncludeDocProps,
          paramKeepIRM,
          paramCreateBookmarks,
          paramDocStructureTags,
          paramBitmapMissingFonts,
          paramUseISO19005_1,
          ref oMissing);
  
  object SaveToFormat = SaveToFormat = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatDocument97;
  wordDocument.SaveAs(ref objTargetFilePath, ref SaveToFormat, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
  </code></pre>
  
  <p>For Merging several files:</p>
  
  <pre><code>Microsoft.Office.Interop.Word.Document doc = null;
  Microsoft.Office.Interop.Word.Section section = null;
  object sectionBreakNextPage = (object)WdBreakType.wdSectionBreakNextPage;
  
  WordApp.Visible = false;
  doc = this.WordApplication.Documents.Add(ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing);
  
  if (doc != null)
  {
      doc.Activate();
      int fileCount = sourceFiles.Length;
      String fileName = string.Empty;
  
      for (int fileIndex = 0; fileIndex &lt; fileCount; fileIndex++)
      {
          fileName = sourceFiles[fileIndex];
          if (System.IO.File.Exists(fileName))
          {
              section = doc.Sections.Last;
              //delink the current section's header &amp; footer from previous section's header &amp; footer
              section.Headers[WdHeaderFooterIndex.wdHeaderFooterFirstPage].LinkToPrevious = false;
              section.Footers[WdHeaderFooterIndex.wdHeaderFooterFirstPage].LinkToPrevious = false;
              section.Headers[WdHeaderFooterIndex.wdHeaderFooterPrimary].LinkToPrevious = false;
              section.Footers[WdHeaderFooterIndex.wdHeaderFooterPrimary].LinkToPrevious = false;
              section.Headers[WdHeaderFooterIndex.wdHeaderFooterEvenPages].LinkToPrevious = false;
              section.Footers[WdHeaderFooterIndex.wdHeaderFooterEvenPages].LinkToPrevious = false;
  
              section.Range.InsertFile(fileName, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing);
              //if it is last iteration, do'nt insert break
              if (fileIndex &lt; fileCount - 1)
              {
                  object rangeStart = (object)(section.Range.End - 1);
                  doc.Range(ref rangeStart, ref paramMissing).InsertBreak(ref sectionBreakNextPage);
              }
          }
      }
      doc.SaveAs(ref targetFile, ref wordFormat, ref paramMissing,
          ref paramMissing, ref paramMissing, ref paramMissing,
          ref paramMissing, ref paramMissing, ref paramMissing,
          ref paramMissing, ref paramMissing, ref paramMissing,
          ref paramMissing, ref paramMissing, ref paramMissing,
          ref paramMissing);
      return true;
  }
  </code></pre>
  
  <p>Right now, I am receiving the following error:</p>
  
  <p><code>The message filter indicated that the application is busy. (Exception from HRESULT: 0x8001010A (RPC_E_SERVERCALL_RETRYLATER))</code></p>
  
  <p>Can this all be done without using the Word Automation?</p>