Add-in using ribbon throws exception when opening file in protected view

734 views
Skip to first unread message

Chel

unread,
Dec 21, 2015, 12:22:13 PM12/21/15
to Excel-DNA
Here's an odd one. I have Excel-DNA 0.33.9 under Excel 2013, and I'm trying to load an XLL add-in that uses the ribbon. I need to load it indirectly from an XLA, so sometime after the XLA add-in loads, I run this:

  Application.RegisterXLL "c:\path\to\folder\CommandBars.xll"

Specifically, I have code in the Workbook_Open event that uses Application.OnTime to run it.

Under normal circumstances, this works fine. But when I open a file in protected view, the XLL fails to load, throwing an exception:

Initialization [Error] Integration.DnaLibraryAutoOpen Error : COMException - Unknown name. (Exception from HRESULT: 0x80020006 (DISP_E_UNKNOWNNAME))

The call stack looks like this:

  ExcelDna.Integration!ExcelDna.Integration.ExcelDnaUtil.GetApplicationFromWindow(System.IntPtr hWndMain)
  ExcelDna.Integration!ExcelDna.Integration.ExcelDnaUtil.GetApplicationFromWindows15.AnonymousMethod__0(System.IntPtr hWndEnum, System.IntPtr param)
  [Native to Managed Transition] 
  [Managed to Native Transition] 
  ExcelDna.Integration!ExcelDna.Integration.ExcelDnaUtil.GetApplicationFromWindows15()
  ExcelDna.Integration!ExcelDna.Integration.ExcelDnaUtil.GetApplicationFromWindows()
  ExcelDna.Integration!ExcelDna.Integration.ExcelDnaUtil.GetApplication()
  ExcelDna.Integration!ExcelDna.Integration.ExcelDnaUtil.Application.get()
  ExcelDna.Integration!ExcelDna.Integration.ExcelComAddInHelper.LoadComAddIn(ExcelDna.Integration.ExcelComAddIn addIn)
  ExcelDna.Integration!ExcelDna.Integration.DnaLibrary.LoadCustomUI()
  ExcelDna.Integration!ExcelDna.Integration.DnaLibrary.AutoOpen()
  ExcelDna.Integration!ExcelDna.Integration.ExcelIntegration.DnaLibraryAutoOpen()
  [Native to Managed Transition] 
  [Managed to Native Transition] 
  ExcelDna.Loader!ExcelDna.Loader.IntegrationHelpers.DnaLibraryAutoOpen()
  ExcelDna.Loader!ExcelDna.Loader.XlAddIn.XlAutoOpen()
  [AppDomain Transition]
 

I can reproduce this exception by using the CommandBars.dna sample add-in and using Application.RegisterXLL in the Immediate window in the VBE, no XLA required.

Has anyone seen something like this before? Anything that could fix the issue?

Govert van Drimmelen

unread,
Dec 23, 2015, 3:47:23 AM12/23/15
to exce...@googlegroups.com
Hi Chel,

I'm trying to reproduce this using the last part of your message, just loading CommandBars.dna from the VBE.

From the Excel-DNA release .zip file, I take the file Distribution\ExcelDna.xll file and copy into Distribution\Samples\Ribbon\ and rename as CommandBars.xll.

Then I open a fresh Excel 2013 with a blank sheet, press Alt+F11 and in the Immediate window I enter:

    Application.RegisterXLL "C:\Temp\ExcelDna-0.33.9\Distribution\Samples\Ribbon\CommandBars.xll"

The add-in and menu then load without a problem.

Can you help my reproduce the issue without an .xla, or send some detailed instructions on how I could recreated this problem?

Regards,
Govert



From: exce...@googlegroups.com [exce...@googlegroups.com] on behalf of Chel [chelm...@gmail.com]
Sent: 21 December 2015 07:22 PM
To: Excel-DNA
Subject: [ExcelDna] Add-in using ribbon throws exception when opening file in protected view

--
You received this message because you are subscribed to the Google Groups "Excel-DNA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to exceldna+u...@googlegroups.com.
To post to this group, send email to exce...@googlegroups.com.
Visit this group at https://groups.google.com/group/exceldna.
For more options, visit https://groups.google.com/d/optout.

Chel

unread,
Dec 24, 2015, 1:44:17 PM12/24/15
to Excel-DNA
The error will only happen when you open a file in protected view. I think you can reliably get into protected view by opening an Excel file attachment directly from Outlook.
To post to this group, send email to exc...@googlegroups.com.

Govert van Drimmelen

unread,
Dec 24, 2015, 1:58:31 PM12/24/15
to exce...@googlegroups.com
OK, with the mail attachment I can now reproduce the problem.

I'll have a closer look.

-Govert


Sent: 24 December 2015 08:44 PM
To: Excel-DNA
Subject: Re: [ExcelDna] Add-in using ribbon throws exception when opening file in protected view

To post to this group, send email to exce...@googlegroups.com.

Govert van Drimmelen

unread,
Dec 28, 2015, 10:47:11 AM12/28/15
to Excel-DNA
Hi Chel,

OK - I understand the issue now.
Protected view is quite funky. It creates an extra Excel process into which the workbook is loaded, and then hooks that up through a named pipe to the displayed window (that is running on the main Excel process).

The end result is that the type of COM object retrieved from the protected window is a ProtectedViewWindow and not a Workbook.
The code failed because ProtectedViewWindow does not have the expected Application property - that's how we normally get to the COM Application object.

I've checked in a fix that should allow it to work in the protected view case: https://github.com/Excel-DNA/ExcelDna/commit/43a6b4c6c3d8681d9dc7bb954b9b3504349b0d22

For now you'll have to rebuild ExcelDna yourself to try it.
If you do try it, please let me know whether it works for your other scenario too.

Regards,
Govert

Chel

unread,
Dec 28, 2015, 7:56:12 PM12/28/15
to Excel-DNA
Thank you so much for your quick response Govert.

Unfortunately, after building the project in VS2015, I now get another protected view error. A TargetInvocationException (HRESULT 0x80131604) is being thrown on line 120 of ExcelComAddIn.cs

    using (new ComAddInRegistration(progId, friendlyName, description))

I haven't been able to reproduce this yet using the sample add-ins. And again, everything works fine in normal view, but it fails in protected view. I'll keep trying to reproduce this, but do you have any ideas in the meantime?

Chel

unread,
Dec 29, 2015, 11:51:37 AM12/29/15
to Excel-DNA
I can't figure this exception out at all. The registry updates within the constructor seem to be working – I can even see the registry entries it generates – but once control passes back to the calling function (LoadComAddIn) it immediately throws the exception. Anyway, the inner exception is HRESULT 0x800A03EC, and the call stack looks like this:

  ExcelDna.Integration!ExcelDna.Integration.ExcelComAddInHelper.LoadComAddIn(ExcelDna.Integration.ExcelComAddIn addIn) Line 120
  ExcelDna.Integration!ExcelDna.Integration.DnaLibrary.LoadCustomUI() Line 329
  ExcelDna.Integration!ExcelDna.Integration.DnaLibrary.AutoOpen() Line 288
  ExcelDna.Integration!ExcelDna.Integration.ExcelIntegration.DnaLibraryAutoOpen() Line 216

  [Native to Managed Transition] 
  [Managed to Native Transition] 
  ExcelDna.Loader!ExcelDna.Loader.IntegrationHelpers.DnaLibraryAutoOpen() Line 46
  ExcelDna.Loader!ExcelDna.Loader.XlAddIn.XlAutoOpen() Line 313
  [AppDomain Transition] 

If I try to load one of the sample add-ins (TestCSharp.dna) it gets to line 122:

    excelComAddIns = appType.InvokeMember("COMAddIns", BindingFlags.GetProperty, null, app, null, ci);

Then it throws a TargetInvocationException, again with inner exception HRESULT 0x800A03EC. Can you at least reproduce this second exception?

Chel

unread,
Jan 5, 2016, 11:57:38 AM1/5/16
to Excel-DNA
Hi Govert, have you had any opportunity to look at the other exceptions I posted? Can you reproduce the second one?

Thanks,
Chel

Govert van Drimmelen

unread,
Jan 5, 2016, 12:35:03 PM1/5/16
to Excel-DNA
Hi Chel,

Sorry - I've not had a chance yet.
I'll try to have a look tomorrow and let you know.

Regards,
Govert

Govert van Drimmelen

unread,
Jan 7, 2016, 6:38:08 AM1/7/16
to Excel-DNA
Hi Chel,

I can reproduce the problem loading the COM add-in (which enables the ribbon UI) when Excel is running in Protected mode.

The COM error is very common, and doesn't really help explain anything.

The error is similar to the case when Excel is running embedded in another application, e.g. a sheet embedded in a Word document. In the protected Excel case it looks like the process has a "/dde" added to the command line, while in the embedding case there is a "/k" (with the COM error in the same place).

I don't have a plan for a workaround yet.

-Govert



On Tuesday, 5 January 2016 19:35:03 UTC+2, Govert van Drimmelen wrote:
> Hi Chel,
>
> Sorry - I've not had a chance yet.
> I'll try to have a look tomorrow and let you know.
>
> Regards,j
Reply all
Reply to author
Forward
0 new messages