Remote Procedure Call (RPC) errors only thrown when a user is connected via Remote Desktop

0

I'm trying to resolve the following Remote Procedure Call (RPC) error that occurs when an unattended Windows Service application attempts to create a new Excel file via Interop.

Exception: System.Runtime.InteropServices.COMException (0x800706BE): The remote procedure call failed. (Exception from HRESULT: 0x800706BE)
   at Microsoft.Office.Interop.Excel.Workbooks.Add(Object Template)

Here's the code throwing the exception. For context, I included a few lines before and after the culprit code.

' Create Excel objects
Dim objExcelApp As New Excel.Application
Dim objExcelBooks As Excel.Workbooks = objExcelApp.Workbooks 'This is the specific line it fails on every time.
Dim objExcelBook As Excel.Workbook = objExcelBooks.Add
Dim objExcelSheet As Excel.Worksheet = objExcelApp.ActiveSheet

Although this code worked without any issues for the past 7 years, this error started happening immediately upon migrating the service from Windows Server 2008 R2 to Windows Server 2016. Through much trial, error, and hair pulling, I finally discovered that this error is only thrown when someone is connected to the server via Remote Desktop. If no one is connected via Remote Desktop, everything works flawlessly.

What I can't figure out is why does this error only occur when someone is connected to the server via Remote Desktop?

Here are a few things I've tried so far.

  • Added service account to the Administrators group.
  • Component Services -> Computers -> My Computer -> Properties -> COM Security -> Added user to all permissions.
  • Component Services -> Computers -> My Computer -> DCOM Config -> Microsoft Excel Application -> Properties -> Security -> Added user to all permissions.
  • Component Services -> Computers -> My Computer -> DCOM Config -> Windows Management and Instrumentation -> Properties -> Security -> Added user to all permissions.
  • Excel -> File -> Options -> Advanced -> Checked "Ignore other applications that use Dynamic Data Exchange (DDE)"
  • Tried switching from early binding to late binding.
excel
vb.net
excel-interop
asked on Stack Overflow Jun 12, 2020 by Joshua Barker

1 Answer

0

Inspired by Caius Jard's suggestions, I eventually settled on ClosedXML. It's fast, lightweight, free to use for commercial purposes, and doesn't rely on the installation of Excel or the Excel.Interop library to function. The best part is not only did it resolve my issue, fewer lines of code are required to accomplish the same things.

answered on Stack Overflow Feb 27, 2021 by Joshua Barker

User contributions licensed under CC BY-SA 3.0