2

I have Office 2016 preview installed on a Windows 7 (Ultimate edition) developer machine along with VS 2010. I have the following simple C# WinForms application that attempts to create a Word document through automation:

using Word = Microsoft.Office.Interop.Word;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            Word.Application word = new Word.Application(); // <- Causes exception
            ...
        }
}

The application generates the following error:

Additional information: Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).

Most search results for the error in question above involve cases where people are trying to run (earlier) versions of Office programs on actual servers.

Am I missing something?

PS: Office 2016 is itself a strange beast in that it has no entry in Add/Remove Programs, and its deployment tool only has options for selecting applications to exclude from downloading, and no option for repairing an existing installation.

Sabuncu
  • 5,095
  • 5
  • 55
  • 89
  • If you previously had any other Office installed in that same Windows, there's a high probability that it wasn't completely uninstalled or became corrupt. I'd suggest you to uninstall any previous version if you have any as a first step. If problem persists, I'd suggest you to open the Registry Editor, go to HKLM\Typelib and search for "Interop", for each folder there should be only one folder inside, as each folder represent a version; for example: Word 8.5 > Office 2010, 8.6 > 2013 – Camilo Terevinto Dec 02 '15 at 21:55
  • @cFrozenDeath Thanks. I assume you mean HKEY_CLASSES_ROOT, not HKLM? – Sabuncu Dec 02 '15 at 22:00
  • Ooops, yes, that's what I meant – Camilo Terevinto Dec 02 '15 at 22:00
  • @cFrozenDeath Prior to the above error, I was getting an "Unable to cast COM object" error. As you mentioned, I fixed that by removing a superfluous "8.6" entry under a key for Word starting with "00020905-..." (these all end with 46!). That fixed that problem (I also referred to this answer: http://stackoverflow.com/a/12962795/360840 ), but immediately after, I started getting the above (server) error. I am guessing that Office 2016 thinks it is running on a server. – Sabuncu Dec 02 '15 at 22:18
  • I have Windows 10, VS2015 and Office 2016 on my PC, which never had any other Office installed. Let me install Office tools and see what happens – Camilo Terevinto Dec 02 '15 at 22:29
  • BTW, I should have asked. What .NET version are you targeting and from which VS version? – Camilo Terevinto Dec 02 '15 at 22:47
  • @cFrozenDeath Targeting .NET Framework 4 from Visual Studio 2010 Ultimate. – Sabuncu Dec 02 '15 at 22:50
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/96841/discussion-between-cfrozendeath-and-sabuncu). – Camilo Terevinto Dec 02 '15 at 23:24
  • Did you try this with the RTM (the final release) of Office and not the preview? How was Office installed? ClickToRun? MSI? And just for clarification: The term 'server' in the error message refers to 'COM server', it doesn't have anything to do with an actual (physical) server. – Dirk Vollmar Dec 03 '15 at 08:41
  • @DirkVollmar I am not aware of an RTM of Office 2016, it is currently preview only (as part of Office 365 subscriptions), and available only as ClickToRun. I understand the error message, but that message also usually appears when attempting to run Office automation on a Windows server (w/o a UI). – Sabuncu Dec 03 '15 at 14:10
  • @Sabuncu: RTM has been released on 22 September 2015. You can buy it here: https://products.office.com/en-US/buy/compare-microsoft-office-products?tab=opc (or download it within your Office 365 subscription). – Dirk Vollmar Dec 03 '15 at 16:02
  • @DirkVollmar Thank you for the information and the very helpful link. The link does not help w/ finding a source for a non-clicktorun package, but it's a start. I will ask MS support for help in locating an MSI package. Again, thank you. – Sabuncu Dec 03 '15 at 20:07
  • @Sabuncu: Why not just install the ClickToRun version? Your code should work no matter how Office got installed. – Dirk Vollmar Dec 04 '15 at 09:04
  • @DirkVollmar In my experience I found ClickToRun prone to failure during download. I had to start over couple times. – Sabuncu Dec 04 '15 at 15:14
  • @cFrozenDeath Hi, did you see my comments in the chat room? Thanks. – Sabuncu Dec 05 '15 at 11:59
  • @Sabuncu no, I was not notified of your latest message in the chat room. Thanks for letting me know, will do. – Camilo Terevinto Dec 05 '15 at 12:55

1 Answers1

2

I tried to mimic your system as much as possible, by creating a WinForms project and targeting .NET 4.0. I'm able to create a Word.Application object without any exception.
I'm pretty sure that you are getting the error due to a corrupt Windows Registry, likely corrupted by Office itself.

There are 3 more things you can do before giving up:

  1. Go here and follow the steps to clean up the Registry using scanreg /fix
  2. Uninstall every Office product, open the Registry and delete EVERY key related to Office, then install 2016 again (make sure to backup all your data first)
  3. Reinstall Windows.

I worked in an application support position where the application was very integrated with Excel and Word through add-ins, and I had to research and explain to the development team (another vendor) why this happened and how it can be solved in some cases.
Until I found step 1 above and the steps I told you in my first comment to your question, every single case was solved using step 3.

Camilo Terevinto
  • 31,141
  • 6
  • 88
  • 120