8

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.

skaffman
  • 398,947
  • 96
  • 818
  • 769
the_drow
  • 18,571
  • 25
  • 126
  • 193
  • 1
    *"enough memory on the server to launch a spaceship"* - errm Sir, **1MB of RAM** is definitely not enough to run whatever you're doing with Word!!! http://www.popsci.com/node/31716 – Dennis G Oct 27 '10 at 10:05
  • @moontear: LOL! but it's not helping :( – the_drow Oct 27 '10 at 10:28
  • For historical (and mine) reasons I'd like to point out that the spaceship in question is likely Saturn V with it's whopping 32kB of RAM and the updated question means that the server had likely 256MB of RAM? Or is it a more modern spaceship with 1MB of RAM and the server had 8GB of RAM? :) – Honza Pačuta Aug 15 '23 at 11:53

4 Answers4

8

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.

the_drow
  • 18,571
  • 25
  • 126
  • 193
  • 1
    Wow, the Desktop folder fixed things for me. I had already mucked around with Component Services setting permissions on the DCOM object for Word so maybe that made your step 2 unnecessary for me. But the folder thing definitely made things start working on Windows Server 2008 for me. Thanks. – sliderhouserules May 10 '11 at 20:09
  • @sliderhouserules: You're very lucky than. – the_drow May 10 '11 at 21:19
  • This just saved me from bashing my head open with my keyboard. All I needed was creating the desktop folder, and it worked great. – Bill Sambrone Oct 24 '11 at 19:10
  • @BillSambrone: It might break at some point. Just making sure you know that. Prefer desktop apps for communicating with COM objects. – the_drow Oct 25 '11 at 00:34
3

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:

Dennis G
  • 21,405
  • 19
  • 96
  • 133
  • +1 for this comment about running word on the server. Actually that might not the the greatest idea in the world in any case. what you might have better luck with is setting up a separate machine, that receives "requests" to generate documents FROM the webserver, generates them and then signals the webserver to pick them up. Might be simpler in the long run. – DarinH Nov 01 '10 at 20:13
  • from 'C:\Work\Danel.Nursing\Crm.DocumentGeneration.Printing\DocumentsPrinter.cs' parhaps – the_drow Nov 10 '10 at 17:09
0

Update Microsoft has fixed the issue with an update.
For all who have the issue with the regional format please update your Office to the Version 1902 (Build 11328.20158).
You might need to change to the monthly update channel to get it.

For Windows 10 1809 users the issue might come from the windows regional format settings. It seems that there is an issue when you use a special regional format like "English (Switzerland)". If you change it to "English (UK)" everything works fine. The information about this I have found here

Hope this helps someone who still face the issue.

-3

Your scenario is NOT supported by Microsoft according to the KB article Considerations for server-side Automation of Office which states that

Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

The article then goes over alternatives to server-side automation one of which is Open XML. You might want to check this article out if you haven't already done so.

Mehmet Aras
  • 5,284
  • 1
  • 25
  • 32