1

I'm trying to create, open, read/write to/from .docx files from a windows 8.1 universal App. I'm using Visual Studio 2013.

When I initialize a Interop.Word.Application

Microsoft.Office.Interop.Word.Application application = new Microsoft.Office.Interop.Word.Application();

I get an error

An exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll but was not handled in user code

Additional information: Creating an instance of the COM component with CLSID 
{000209FF-0000-0000-C000-000000000046} using CoCreateInstanceFromApp failed due 
to the following error: 80040154 Class not registered (Exception from HRESULT:
0x80040154 (REGDB_E_CLASSNOTREG)). Please make sure your COM object is in the 
allowed list of CoCreateInstanceFromApp.

I have looked around and haven't been able to find anything that matches my problem. I've seen this exception for insufficient permissions, but I've run as admin, and no luck.

Any help is appreciated. Let me know if you need more information.

EDIT 1

I did do something weird while creating this app. I wasn't able to add a reference to Microsoft.Office.Interop the way I've been able to in the past, so I followed some instructions I found online, and added them by just pointing to

C:\Program Files (x86)\Microsoft Visual Studio 12.0\Visual Studio Tools for Office\PIA\Office15\Microsoft.Office.Interop.Word.dll

I'm not sure if that helps, but it was the only thing that I did that seemed abnormal.

trueCamelType
  • 2,198
  • 5
  • 39
  • 76

2 Answers2

3

The problem is the following (excerpt from the exception message):

Please make sure your COM object is in the allowed list of CoCreateInstanceFromApp.

Windows Store apps cannot load arbitrary COM objects. Only a limited (built-in) set of COM and Win API is available to Store / Universal apps. And Microsoft Office is not in the list of allowed COM objects.

So what are your options? You can either

  • Create a desktop app instead,
  • Move document processing to the server side (which comes with a whole different set of issues if you are going to use COM interop),
  • Use an OpenXML based approach on the server (OpenXML SDK won't work in a Store App either)
  • Write your own code that modifies the OpenXML package directly (e.g. using XDocument)
  • Use a Brokered Windows Runtime Components for side-loaded Windows Store apps (this likely isn't an easy option when dealing with Office applications)
Dirk Vollmar
  • 172,527
  • 53
  • 255
  • 316
0

Did you try to compile the solution in x86 mode? Possibly these COM objects are 32 bit on your installation, and thefactory will fail if you call them from an "All CPU" executable on a 64 bit machine.

Felice Pollano
  • 32,832
  • 9
  • 75
  • 115
  • If I change it to x86 mode (assuming I'm doing it correctly from [these](http://stackoverflow.com/questions/8333468/how-to-add-x64-or-any-cpu-as-a-build-option-in-visual-studio-2010-from-consol) instructions, then I get the same error in x86. – trueCamelType Nov 24 '15 at 06:38
  • Thank you for the help so far. I edited the question with some (hopefully) useful information. – trueCamelType Nov 24 '15 at 06:41