Error accessing COM components
Asked Answered
K

6

30

I built an add-in for Microsoft Office Word. There isn't an issue using the add-in when Word is ran as Administrator, but when it's not ran as an Administrator, there are two common exceptions accessing Ribbon elements.

The first Exception:

Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Office.Core.IRibbonUI'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{000C03A7-0000-0000-C000-000000000046}' failed due to the following error:  could not be found. (Exception from HRESULT: 0x80030002 (STG_E_FILENOTFOUND)).
   at Microsoft.Office.Core.IRibbonUI.InvalidateControl(String ControlID)

This error occurs when the Control is invalidated by the following code:

ribbon.InvalidateControl("control-id");

And the second Exception:

Unable to cast COM object of type 'Microsoft.Office.Interop.Word.ApplicationClass' to interface type 'Microsoft.Office.Interop.Word._Application'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{00020970-0000-0000-C000-000000000046}' failed due to the following error:  could not be found. (Exception from HRESULT: 0x80030002 (STG_E_FILENOTFOUND)).
   at Microsoft.Office.Interop.Word.ApplicationClass.get_Selection()

This error occurs on the last line of the following code:

object wdStory = Word.WdUnits.wdStory;
object wdMove = Word.WdMovementType.wdMove;
WrdApp.Selection.EndKey(ref wdStory, ref wdMove)

How can I fix this problem?

Kristiekristien answered 18/10, 2012 at 14:55 Comment(7)
Does it work on other computers? I broke the registry the other day (on a coworkers computer no less) and was experiencing issues similar to this will all programs that used COM components. If it works on another computer, I'll explain what I did to fix it.Mirthamirthful
Yes, works in development computer. Only in the test machine is not working. Maybe because I install (and unistall) many versions of Office (2007, 2007-64, 2010, 2010-64)Kristiekristien
Oh dear. Well, what operating system is the test machine running?Mirthamirthful
Windows 7 64bits with Office 2007 32bitsKristiekristien
But why when I'm running as administrator everything works fine?Kristiekristien
I don't know, but I had the same issue. Running programs as an administrator worked, but most would encounter errors and crash otherwise. I'll post an answer with what I did.Mirthamirthful
I removed my answer because it didn't work for you, and we don't need people going and blowing up their registries by trying risky solutions like this.Mirthamirthful
K
59

Problem solved!

I have previously installed Office 2010, so there are some inconsistences in Windows Registry. To fix them, open the regedit and find for the CLSID from the error.

You will find something like that for the second error:

HKEY_CLASSES_ROOT\Interface\{00020970-0000-0000-C000-000000000046}

With the subkeys:

  • ProxyStubClsid
  • ProxyStubClsid32
  • TypeLib

Take a look at the (Default) and Version values inside of TypeLib.

Now find the node below, using the (Default) value as <TypeLib ID>.

HKEY_CLASSES_ROOT\TypeLib\<TypeLib ID>\<version>

As child of this elements you will find more than one element, one of then is the Version of the first registry. If you inspect the others elements, you will find that they point to nothing. Remove the others!!! It's solved!

Kristiekristien answered 18/10, 2012 at 20:2 Comment(3)
@Wug, problem found! Thanks for help me.Kristiekristien
Had the same problem when rolling back from Office 2013 to Office 2010. This solution worked perfectly.Damiano
Thanks so much! Spent all day debugging an add-in on one persons computer and this solved itCaelian
K
8

I started getting the same exception after upgrading to the latest Office version. I tried a number of suggested fixes including cleaning up the registry in a way similar to what @Victor described.

What eventually helped (even though it might have been a combination of factors) was 'repairing' the installation:

Programs and Features → latest Office version → Repair.

Kagu answered 13/10, 2015 at 17:37 Comment(3)
This worked for me also with Office 365 and Windows 7. Thank you!Cretinism
Works for me, I have only VS2010 and Office 2016Abdul
This worked for me using VS2017 and O365. Thanks a bunch!Fairing
N
1

The office repair worked for me. In my case I had installed Project which I believe altered the config and was unable to call up a procedure to migrate data from an excel workbook to SQL

Nantucket answered 19/1, 2018 at 10:5 Comment(0)
F
0

Just install Office 2010 / MS word / .NET Programmability Support.

Fury answered 17/9, 2015 at 6:46 Comment(0)
C
0

@Victor You got me headed on the right path. My issue was not multiple values in the registry but rather, a missing value that Office365 never added. Thanks to you I was able to find my own resolution. A thousand thousand thanks.

Details are here for anyone still looking for a resolution.

Corrade answered 8/3, 2016 at 0:53 Comment(0)
L
0

I got the same problem today with VS2015 and Office 2013. Changing the Platform target to x64 worked for me.

Lardner answered 20/3, 2017 at 5:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.