Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

COMException (0x800A13E9) - Word interop services

I am getting this stacktrace:

System.Runtime.InteropServices.COMException (0x800A13E9): Word ðú÷ì ááòéä.
   at Microsoft.Office.Interop.Word.Documents.Add(Object& Template, Object& NewTemplate, Object& DocumentType, Object& Visible)
   at Crm.DocumentGeneration.Printing.DocumentsPrinter.MergeDocuments(ApplicationClass& wordApp, IEnumerable`1 printDataItems, String tempDirectory, String template) in C:\Work\Danel.Nursing\Crm.DocumentGeneration.Printing\DocumentsPrinter.cs:line 249

After googling a bit it seems that COMException (0x800A13E9) is out of memory exception but there is enough memory on the server to launch a spaceship 8192 spaceships.
Here is the function call:

Document document = wordApp.Documents.Add(ref defaultTemplate, ref missing, ref missing, ref missing);

Nothing is null or invalid with defaultTemplate, I checked.

like image 988
the_drow Avatar asked Oct 27 '10 09:10

the_drow


2 Answers

Here's the solution I found:

  1. Put a folder called Desktop on C:\Windows\SysWOW64\config\systemprofile (Yes I know. WTF?)
  2. Open Regedit, Go to HKEY_LOCAL_MACHINE\SOFTWARE\Classes\AppId and edit the two enteries that have a Guid ending with 46. Delete every key they have and add a new key called RunAs with the value of Interactive User

After that, start praying. It doesn't work if you access through a terminal server. Which is kind of a problem for me hehe.

EDIT: The problem with the terminal server was that only an Administrator is allowed to raise COM objects so what you have to do is impersonate to an Administrator.

like image 61
the_drow Avatar answered Nov 15 '22 12:11

the_drow


Sorry 'bout that 1MB reference... I just had to jump on that one.

When automating Office Applications make sure, that you use a local account on the server with permissions for the Word COM+ object as well as the documents you are trying to work on.
There are several posts relating to your problem pointing at the account issue:

  • ASP.NET 1.1 + 2003 Server + open Word document = InteropServices.COMException(0x800A13E9)
    • suggests that you should use an "interactive user" instead of the "launching user"
  • Error while calling MS-Word from ASP.NET
    • suggests creating a local user granting all permissions for the Word COM+ object
like image 20
Dennis G Avatar answered Nov 15 '22 12:11

Dennis G