Unable to cast COM object of type 'System.__ComObject' to interface type 'AddinExpress.MSO.IRibbonUI' ... TYPE_E_LIBNOTREGISTERED

Add-in Express™ Support Service
That's what is more important than anything else

Unable to cast COM object of type 'System.__ComObject' to interface type 'AddinExpress.MSO.IRibbonUI' ... TYPE_E_LIBNOTREGISTERED
Error pops up when Word and Excel open, but our add-in loads and works anyway 
Ira Whitman




Posts: 56
Joined: 2010-01-21
I've found other posts for "Unable to cast COM object ... AddinExpress.MSO.IRibbonUI" but each of those ended with the error code E_NOINTERFACE. This one is a little different.

The complete message is:
Unable to cast COM object of type 'System.__ComObject' to interface type 'AddinExpress.MSO.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: Library not registered. (Exception from HRESULT: 0x8002801D (TYPE_E_LIBNOTREGISTERED)).

Furthermore, despite the error, the add-in seems fully functional (including the Ribbon).

The error is occurring on one customer site on Office 2010 and on computer in our tech support department, which has Office 2016.

We've reinstalled Office, checked PIAs, captured "fusion" load logs. We're not sure what isn't registered or how to make it so. Please assist.
Posted 14 Jul, 2016 15:45:59 Top
Andrei Smolin


Add-in Express team


Posts: 18829
Joined: 2006-05-11
Hello Ira,

I assume your add-in is built using the .NET Framework 4.X. If this is so, try to reinstall .all of the NET Frameworks 4.X on that machine in the correct order. If the particular .NET Framework version that you use isn't installed, install it as well.

Interops for what Office version(s) does your add-in use?


Andrei Smolin
Add-in Express Team Leader
Posted 15 Jul, 2016 03:48:22 Top
Ira Whitman




Posts: 56
Joined: 2010-01-21
Hello Andrei,

Yes, our add-in is built using 4.5.2. I'm unclear on why or how we would install each 4.x in order. Wouldn't reinstalling 4.5.2 cover 4.0 and 4.5? We are trying that today.

We use interops for Office 2003.

Thank you,

- Ira
Posted 15 Jul, 2016 08:29:50 Top
Andrei Smolin


Add-in Express team


Posts: 18829
Joined: 2006-05-11
Ira,

Ira Whitman writes:
Wouldn't reinstalling 4.5.2 cover 4.0 and 4.5?


I don't know. This is why I would install 4.0, 4.5, and 4.5.2 in this order.

In what moment do you get the exception? Is there a stack trace? Does the add-in work correctly on other machines?


Andrei Smolin
Add-in Express Team Leader
Posted 15 Jul, 2016 08:49:17 Top
Ira Whitman




Posts: 56
Joined: 2010-01-21
Please allow me to answer questions in reverse order:

There are many installations that are problem free, but this problem is occurring on at least one computer for one customer (it happens to be the company president) and on one system within our tech support department. The one in tech support, of course, gives us a great opportunity to diagnose and experiment without bothering the customer.

I don't have a stack trace, and I'm not sure how to capture one. The error occurs as soon as the MS Office application starts up, so we are unable to attach a debugger before it occurs.

Regarding .NET: the system in tech support on which we're debugging is Windows 10, which includes .NET 4.6 as an OS component. It cannot be removed or reinstalled. There is a repair tool for .NET from Microsoft, which has been applied. The customer's system is Windows 8.1 which comes with 4.5.1, so we could uninstall and reinstall 4.5.2. But, we'd prefer to do the diagnosis on our in-house system so we don't bother the customer.

Jumping back to the stack trace:

I can add some try-catch blocks in our AddinModule to capture and the full error with stack trace, but I'm not sure where. I can do so in the ctor, or in any or all of the automatically generated methods, or in the AddinModule_AddinInitialize and/or AddinModule_AddinStartupComplete event handlers. Considering that our add in does function successfully despite the error message popping up, it seems we can rule out some of these. Where do you think I should add try-catches?

Thank you
Posted 19 Jul, 2016 17:14:38 Top
Andrei Smolin


Add-in Express team


Posts: 18829
Joined: 2006-05-11
Hello Ira,

You need to wrap the code that accesses the object model of the add-in's host application in a try/catch block.
Also, you can add a number of debug messages to your code; use System.Diagnostics.Debug.WriteLine(). Build the add-in in the Debug configuration and collect the debug messages at run time using DebugView; see http://technet.microsoft.com/en-us/sysinternals/bb896647.aspx. Make sure you add such a debug message(s) to the code of the constructor in order to find out that the constructor is called and completes correctly.


Andrei Smolin
Add-in Express Team Leader
Posted 20 Jul, 2016 01:28:30 Top
Ira Whitman




Posts: 56
Joined: 2010-01-21
I've captured the stack trace:


System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to interface type 'AddinExpress.MSO.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: Library not registered. (Exception from HRESULT: 0x8002801D (TYPE_E_LIBNOTREGISTERED)).
   at System.StubHelpers.StubHelpers.GetCOMIPFromRCW(Object objSrc, IntPtr pCPCMD, IntPtr& ppTarget, Boolean& pfNeedsRelease)
   at AddinExpress.MSO.IRibbonUI.InvalidateControl(String ControlID)
   at AddinExpress.MSO.ADXRibbonCustomControl.Invalidate()
   at AddinExpress.MSO.ADXRibbonCustomControl.AddinExpress.MSO.IADXRibbonComponent.set_SelectedItemIndex(Int32 value)
   at AddinExpress.MSO.ADXRibbonCustomDropDown.set_SelectedItemIndex(Int32 value)
   at Modules_OI.AddinModule._eclipseClient_GotData(Object sender, EventArgs e) in C:Source16.04Modules.OIAddinModule.cs:line 895


These is a snippet of code, with the point of error marked with comment, "Exception here"


adxRibbonSiteDropDown.Items.Clear();
adxCommandSiteDropDown.Items.Clear();
for (int i = 0; i < _eclipseClient.Instances.SafeLength(); i++)
{
    var instance = _eclipseClient.Instances[i];
    var but = new ADXRibbonButton()
    {
        Caption = instance.CompanyName,
        //ScreenTip = instance.Name, not needed because we only allow one per company now
        //SuperTip = instance.Description, useless/confusing because it is not exposed in UI
        Tag = i
    };
    adxRibbonSiteDropDown.Items.Add(but);
    adxCommandSiteDropDown.Items.Add(instance.CompanyName); // strings only here
    DebugLog(String.Format("Instance {0}:{1}", i, _eclipseClient.Instances[i].CompanyName));
}
if (_eclipseClient.CurrentInstanceIndex >= 0)
{
    DebugLog(String.Format("CurrentInstanceIndex: {0}; Instances Count:{1}", _eclipseClient.CurrentInstanceIndex,     _eclipseClient.Instances.Length));
    adxRibbonSiteDropDown.SelectedItemIndex = _eclipseClient.CurrentInstanceIndex; // <--- Exception Here
    // The above works because there is a design-time selected item
    // http://www.add-in-express.com/forum/read.php?FID=5&TID=11667
    <etc.>


blue is an AddinExpress.MSO.ADXRibbonDropDown created by the designer.
This is the automatic code it generated:


// 
// adxRibbonSiteDropDown
// 
this.adxRibbonSiteDropDown.Caption = "companyText";
this.adxRibbonSiteDropDown.Id = "adxRibbonDropDown_ffc78975f3244822924a6714d200c2b7";
this.adxRibbonSiteDropDown.ImageTransparentColor = System.Drawing.Color.Transparent;
this.adxRibbonSiteDropDown.Items.Add(this.adxRibbonItem1);
this.adxRibbonSiteDropDown.Ribbons = ((AddinExpress.MSO.ADXRibbons)((((((AddinExpress.MSO.ADXRibbons.msrOutlookMailRead | AddinExpress.MSO.ADXRibbons.msrOutlookMailCompose) 
| AddinExpress.MSO.ADXRibbons.msrExcelWorkbook) 
| AddinExpress.MSO.ADXRibbons.msrWordDocument) 
| AddinExpress.MSO.ADXRibbons.msrPowerPointPresentation) 
| AddinExpress.MSO.ADXRibbons.msrOutlookExplorer)));
this.adxRibbonSiteDropDown.SelectedItemIndex = 0;
this.adxRibbonSiteDropDown.ShowCaption = false;
this.adxRibbonSiteDropDown.SizeString = "This is a very long company name";
this.adxRibbonSiteDropDown.OnAction += new AddinExpress.MSO.ADXRibbonOnActionSelected_EventHandler(this.adxRibbonSiteDropDown_OnAction);


Its Items collection is filled, as you can see, with some ADXRibbonButtons.
I've verified through the DebugLog statement that the value to which SelectedItemIndex is set is 3, and that 7 ADXRibbonButton objects have been added to adxRibbonSiteDrop.Items.

The add-in-express.com/forum reference is a solution to an issue we once hit when first developing this add-in. It was resolved simply by setting SelectedItemIndex = 0 in the designer.

So, it seems that the ribbon fails to repaint as expected when its SelectedItemIndex is changed. Can we determine why?

By the way, I previously reported that our add-in runs successfully despite the error. I now see that the dropdown doesn't get set as expected and other UI changes which follow don't occur. We cannot just catch and suppress this error.
Posted 20 Jul, 2016 12:28:22 Top
Andrei Smolin


Add-in Express team


Posts: 18829
Joined: 2006-05-11
Hello Ira,

{000C03A7-0000-0000-C000-000000000046} is the GUID of the IRibbonUI COM interface. I suggest that you repair or even re-install Office. If you have several Office versions installed, you need to repair/reinstall them in the oldest-to-newest order.


Andrei Smolin
Add-in Express Team Leader
Posted 21 Jul, 2016 01:30:37 Top
Ira Whitman




Posts: 56
Joined: 2010-01-21
I've mentioned we have two cases: one is in our tech support department and one is the customer's system.

The following has been done on the customer system, as logged by the senior support tech working on it:

"So far i have:
repaired office
Uninstalled and reinstall office.
Deleted all registry entries with this CLSID, repaired office
Verified .netframework 4.5 was installed."

And on our tech support system, the following was done:

"...I have uninstalled everything Office related and reinstalled and still have the error on my own machine.
Also, nobody can expect customers to wipe their machines clean and install Office 2016 fresh.
We need to investigate this further."

Do you have a recommendation -- other than reinstall the OS -- as to how can we truly purge old Office installations when repair, uninstall, and reinstall have failed to resolve this issue?
Posted 21 Jul, 2016 08:46:30 Top
Andrei Smolin


Add-in Express team


Posts: 18829
Joined: 2006-05-11
Ah, I'm sorry.

I've noticed that you create controls without supplying the container. Could you please check if this causes the issue?

this.adxRibbonButton1 = new AddinExpress.MSO.ADXRibbonButton(this.components);

Ira Whitman writes:
Do you have a recommendation -- other than reinstall the OS -- as to how can we truly purge old Office installations when repair, uninstall, and reinstall have failed to resolve this issue?


Do you have several Office versions installed on these machines? If so, please check https://support.microsoft.com/en-us/kb/2784668.


Andrei Smolin
Add-in Express Team Leader
Posted 21 Jul, 2016 09:48:11 Top