title: The remote procedure call failed Excel inside IIS
body: <p>When I try to download an Excel file using asp.net I get this Error</p>
  
  <blockquote>
    <p>The remote procedure call failed. (Exception from HRESULT: 0x800706BE)
    Description: An unhandled exception occurred during the execution of
    the current web request. Please review the stack trace for more
    information about the error and where it originated in the code. </p>
    
    <p>Exception Details: System.Runtime.InteropServices.COMException: The
    remote procedure call failed. (Exception from HRESULT: 0x800706BE)</p>
    
    <p>Source Error: </p>
  
  <pre><code>       xlworkbook.SaveAs(Path)
         xlworkbook.Close()
         xlAPP.Quit() 'error on this line
  </code></pre>
    
    <p>[COMException (0x800706be): The remote procedure call failed.
    (Exception from HRESULT: 0x800706BE)]<br>
    Microsoft.Office.Interop.Excel.ApplicationClass.Quit() +0</p>
  </blockquote>
  
  <p>and sometimes the error is </p>
  
  <blockquote>
    <p>The remote procedure call failed. (Exception from HRESULT: 0x800706BE)
    Description: An unhandled exception occurred during the execution of
    the current web request. Please review the stack trace for more
    information about the error and where it originated in the code. </p>
    
    <p>Exception Details: System.Runtime.InteropServices.COMException: The
    remote procedure call failed. (Exception from HRESULT: 0x800706BE)</p>
    
    <p>Source Error:</p>
  
  <pre><code>        xlworkbook.SaveAs(Path)
          xlworkbook.Close()   'line triggering the error
          xlAPP.Quit()
  </code></pre>
    
    <p>[COMException (0x800706be): The remote procedure call failed.
    (Exception from HRESULT: 0x800706BE)]</p>
  
  <pre><code>Microsoft.Office.Interop.Excel._Workbook.Close(Object SaveChanges, Object Filename, Object RouteWorkbook) +0
  </code></pre>
  </blockquote>
  
  <p><strong>I DID ALL The Below Steps</strong></p>
  
  <ol>
  <li><p>Open Windows Explorer</p></li>
  <li><p>Depending on whether you installed a 32bit or 64bit version of
  office you will need to do one (or both) of the following: 32bit
  Office installation: Navigate to
  C:\Windows\System32\config\systemprofile 64bit Office installation:</p></li>
  <li><p>Navigate to C:\Windows\SysWOW64\config\systemprofile</p></li>
  <li><p>Verify the folder "Desktop" exists (create it if it's not there)</p></li>
  <li><p>Right click > Properties</p></li>
  <li><p>On the security tab: Add the account under which the site is running
  (eg: Network Service) with default permissions (Read &amp; execute; List
  folder contents; Read)</p></li>
  </ol>
  
  <p>In the dcomconfig utility,</p>
  
  <p>go to Component Services --> Computers --> My Computer --> DCom Config --> Microsoft Excel Application (and Powerpoint)</p>
  
  <p>Right click it and go to properties. Go to security tab. Under Security</p>
  
  <p>1, Launch &amp; Activation Permissions --> Choose customise and click Edit. Add User Network Service and check everything under Allow for it.</p>
  
  <ol start="2">
  <li>Do the same for Access Permissions and Configuration Permissions.</li>
  </ol>
  
  <p>Then click Apply and close everything.</p>
  
  <p><strong>Sometimes I can download the file but sometimes I got this error
  Any ideas why?</strong></p>