Exception in SetHostApplication

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

Exception in SetHostApplication
 
Subscribe
John White




Posts: 5
Joined: 2024-05-21
Hello,

One of our users is getting an exception popup "randomly" when our addin is installed. I assume that this is caused by the addin being initialized by some application other than Excel (which the only application we support.) Is there any way to determine what application is triggering this initialization? Can we prevent this other application from trying to initialize the addin?

From the exception:


Detailed technical information follows:

Date and Time:             2024-05-09 8:28:34 AM
Machine Name:              (redacted)
IP Address:                (redacted)
Current User:              (redacted)

Application Domain:        C:UsersnnamAppDataLocalApps.0P5M...
Assembly Codebase:         file:///C:/Users/annam/AppData/Local/Apps/2.
Assembly Full Name:        AddinExpress.MSO.2005, Version=8.6.4408
Assembly Version:          8.6.4408.0

Exception Source:          AddinExpress.MSO.2005
Exception Type:            System.ArgumentException
Exception Message:         Unknown application.
Parameter name: name
Exception Target Site:     SetHostApplication

---- Stack Trace ----
   AddinExpress.MSO.ADXAddinModule.SetHostApplication()
       AddinExpress.MSO.2005.DLL: N 0000 (0x0) IL
   AddinExpress.MSO.ADXAddinModule.AddinExpress.MSO.IDTExtensibility
       AddinExpress.MSO.2005.DLL: N 0082 (0x52) IL


Thanks!
Posted 23 May, 2024 14:37:38 Top
Andrei Smolin


Add-in Express team


Posts: 18965
Joined: 2006-05-11
Hello John,

Please make sure that Excel is started interactively on that machine, not programmatically.

Regards from Poland (GMT+2),

Andrei Smolin
Add-in Express Team Leader
Posted 24 May, 2024 07:57:00 Top
John White




Posts: 5
Joined: 2024-05-21
I believe it is being started programmatically. The ADXLoader.log from immediately before the exception shows the command-line has the "-Embedding" flag. Am I interpreting this correctly?


Add-in Express Loader Log File: 05/09/2024 08:28:31:815

Startup directory: C:UsersnnamAppDataLocalApps.0P5M5XL2T.TRZBXX0HLL.M78ena_dfa8d8047b427363_0001.07e8_1edab34f93c9b575
Loader version: 7.5.4072.0
Operating System: Microsoft  (build 22631), 64-bit
Process Owner: Administrator
Command Line: "C:Program FilesMicrosoft OfficeRootOffice16EXCEL.EXE" -Embedding
Run 'As Administrator': No
Process Elevated: No
Integrity Level: Medium
UAC (User Account Control): On
------------------------------------------------------------------------
08:28:31:816 3260 32096 Start - xlAutoOpen.
08:28:31:816 3260 32096 Creating a new instance of the XLL loader.
08:28:31:816 3260 32096 Loading mscoree.dll
08:28:31:817 3260 32096 Success.
08:28:31:817 3260 32096 Getting the CLSID of the managed XLL class.
08:28:31:817 3260 32096 Success.
08:28:31:817 3260 32096 Loading the configuration from the system registry.
08:28:31:817 3260 32096 Getting the latest CLR version.
08:28:31:818 3260 32096 The latest CLR version is 'v4.0.30319'.
08:28:31:818 3260 32096 The configuration has been loaded successfully.
08:28:31:818 3260 32096     Runtime version: v4.0.30319.
08:28:31:818 3260 32096     Assembly name: Vena, Version=1.2024.501.1657, Culture=neutral, PublicKeyToken=null.
08:28:31:818 3260 32096     Class name: VenaSPMAddIn.VenaXLL.
08:28:31:818 3260 32096     Registry key: CLSID{7A04731C-B38D-3904-A4F5-031394A1EEA8}.
08:28:31:818 3260 32096 Attempting to create a new instance of the managed XLL class: CLR - v4.0.30319
08:28:31:818 3260 32096 Loading CLR: v4.0.30319.
08:28:31:818 3260 32096 Calling CLRCreateInstance method.
08:28:31:818 3260 32096 Success.
08:28:31:818 3260 32096 Calling GetRuntime method.
08:28:31:818 3260 32096 Success.
08:28:31:818 3260 32096 Checking if the hosting API of .NET Framework v4.0 beta is installed.
08:28:31:830 3260 32096 The hosting API is up to date.
08:28:31:830 3260 32096 Calling GetInterface method for the CorRuntimeHost interface.
08:28:31:830 3260 32096 Success.
08:28:31:830 3260 32096 Starting CLR...
08:28:31:830 3260 32096 Success.
08:28:31:830 3260 32096 Getting the CLR version.
08:28:31:830 3260 32096 The CLR v4.0.30319 has been initialized successfully.
08:28:31:830 3260 32096 Creating a new domain setup.
08:28:31:831 3260 32096 Success.
08:28:31:831 3260 32096 Getting the add-in directory.
08:28:31:831 3260 32096 Success. The directory is 'C:UsersnnamAppDataLocalApps.0P5M5XL2T.TRZBXX0HLL.M78ena_dfa8d8047b427363_0001.07e8_1edab34f93c9b575'
08:28:31:832 3260 32096 The 'shadow copy' is disabled.
08:28:31:832 3260 32096 Creating a new application domain.
08:28:31:837 3260 32096 Success.
08:28:31:837 3260 32096 Getting the base directory for the domain.
08:28:31:837 3260 32096 Success. The directory is 'C:UsersnnamAppDataLocalApps.0P5M5XL2T.TRZBXX0HLL.M78ena_dfa8d8047b427363_0001.07e8_1edab34f93c9b575'.
08:28:31:837 3260 32096 Opening adxloader.dll.manifest.
08:28:31:837 3260 32096 Success. The manifest is 'C:UsersnnamAppDataLocalApps.0P5M5XL2T.TRZBXX0HLL.M78ena_dfa8d8047b427363_0001.07e8_1edab34f93c9b575dxloader.dll.manifest'.
08:28:31:837 3260 32096 Getting the 'assemblyIdentity' element.
08:28:31:837 3260 32096 Success.
08:28:31:837 3260 32096 Getting the 'name' attribute.
08:28:31:837 3260 32096 Success. The name is 'Vena'.
08:28:31:837 3260 32096 Getting the 'name' attribute.
08:28:31:837 3260 32096 Success. The class name is 'VenaSPMAddIn.VenaXLL'.
08:28:31:837 3260 32096 Attempting to create a new instance of the XLL class.
08:28:31:856 3260 32096 Success.
08:28:31:856 3260 32096 Getting the dispid of the 'autoOpen' method.
08:28:31:857 3260 32096 Success.
08:28:31:857 3260 32096 Getting the dispid of the 'autoClose' method.
08:28:31:857 3260 32096 Success.
08:28:31:857 3260 32096 Getting the dispid of the 'autoAdd' method.
08:28:31:857 3260 32096 Success.
08:28:31:857 3260 32096 Getting the dispid of the 'autoRemove' method.
08:28:31:857 3260 32096 Success.
08:28:31:857 3260 32096 Getting the dispid of the 'autoFree' method.
08:28:31:857 3260 32096 Success.
08:28:31:857 3260 32096 Getting the dispid of the 'autoFree12' method.
08:28:31:857 3260 32096 Success.
08:28:31:857 3260 32096 Getting the dispid of the 'addInManagerInfo' method.
08:28:31:857 3260 32096 Success.
08:28:31:857 3260 32096 Getting the dispid of the 'addInManagerInfo12' method.
08:28:31:857 3260 32096 Success.
08:28:31:857 3260 32096 Getting the dispid of the 'Dispose' method.
08:28:31:857 3260 32096 Success.
08:28:31:857 3260 32096 Getting the dispid of the 'initialize4' method.
08:28:31:857 3260 32096 Success.
08:28:31:857 3260 32096 Invoking the 'initialize4' method.
08:28:32:639 3260 32096 Success.
08:28:32:639 3260 32096 The managed XLL class has been created successfully.
08:28:32:639 3260 32096 Forwarding xlAutoOpen to the managed code.
08:28:32:662 3260 32096 Success.
08:28:34:139 3260 32096 Start.
08:28:34:139 3260 32096 Reading the registry key 'HKEY_CLASSES_ROOTCLSID{5B2BB6DA-A7F8-4093-94A7-55A4DBC30C54}'
08:28:34:139 3260 32096 Success. The registry key 'HKEY_CLASSES_ROOTCLSID{5B2BB6DA-A7F8-4093-94A7-55A4DBC30C54}' is closed.
08:28:34:139 3260 32096 Converting the '{4BA250A6-8BCA-46A6-982A-F340081187C3}' CLSID from string.
08:28:34:139 3260 32096 Success.
08:28:34:139 3260 32096 Attempting to get the class object by the '{4BA250A6-8BCA-46A6-982A-F340081187C3}' CLSID.
08:28:34:139 3260 32096 Success.
08:28:34:139 3260 32096 Creating a new instance of the add-in loader.
08:28:34:139 3260 32096 Success.
08:28:34:139 3260 32096 Loading the configuration from the system registry.
08:28:34:139 3260 32096 Getting the latest CLR version.
08:28:34:139 3260 32096 The latest CLR version is 'v4.0.30319'.
08:28:34:139 3260 32096 The configuration has been loaded successfully.
08:28:34:139 3260 32096     Runtime version: v4.0.30319.
08:28:34:139 3260 32096     Assembly name: Vena.
08:28:34:139 3260 32096     Class name: VenaSPMAddIn.AddinModule.
08:28:34:139 3260 32096     Registry key: CLSID{5B2BB6DA-A7F8-4093-94A7-55A4DBC30C54}.
08:28:34:139 3260 32096 Attempting to create a new instance of the managed add-in class: CLR - v4.0.30319
08:28:34:139 3260 32096 Creating an instance of the managed class. Assembly identity: 'Vena'
08:28:34:298 3260 32096 Success.
08:28:34:298 3260 32096 Unwrapping the managed class.
08:28:34:301 3260 32096 Success.
08:28:34:301 3260 32096 Querying the add-in extensibility.
08:28:34:302 3260 32096 Success.
08:28:34:302 3260 32096 Querying the custom task panes.
08:28:34:302 3260 32096 Success.
08:28:34:302 3260 32096 Querying the ribbon extensibility.
08:28:34:302 3260 32096 Success.
08:28:34:302 3260 32096 Querying the form regions.
08:28:34:302 3260 32096 Success.
08:28:34:302 3260 32096 Getting the dispid of the 'Dispose' method.
08:28:34:305 3260 32096 Success.
08:28:34:305 3260 32096 The managed add-in class has been created successfully.
08:28:34:315 3260 32096 Start - xlAutoClose.
08:28:34:315 3260 32096 Forwarding xlAutoClose to the managed code.
08:28:34:315 3260 32096 Success.
Posted 24 May, 2024 15:37:31 Top
Andrei Smolin


Add-in Express team


Posts: 18965
Joined: 2006-05-11
Hello John,

Don't know what -Embedding means; it isn't listed at https://support.microsoft.com/en-us/office/command-line-switches-for-microsoft-office-products-079164cd-4ef5-4178-b235-441737deb3a6#Category=Excel.

I'd expect that Excel won't load your XLL if started programmatically. This is by default, and you would take special measures to load your XLL in this scenario.

But the real test is: check the ExcelApp.UserControl property; see https://learn.microsoft.com/en-us/office/vba/api/excel.application.usercontrol.

If VBA is enabled in Excel on that machine, the fastest way to check that property is this:
1) start Excel,
2) press Alt+F11 to open the VBA editor,
3) press Ctrl+G to open the Immediate window,
4) type '?Application.UserControl' (without quotes) and press Enter.

For me this prints True, if Excel is started interactively.

John White writes:
Assembly Version: 8.6.4408.0
Loader version: 7.5.4072.0


The loader version should correspond to the Add-in Express version used.

Regards from Poland (GMT+2),

Andrei Smolin
Add-in Express Team Leader
Posted 27 May, 2024 09:41:48 Top
John White




Posts: 5
Joined: 2024-05-21
Hello Andrei,

Thank you for the additional information. From my own experimentation, I believe the -Embedded flag indicates that Excel is loaded in order to work on an embedded Excel file in another application, like PowerPoint or Outlook. These experiments also showed that our XLL IS loaded, but our COM addin is not. Does the exception indicate an issue with the XLL or the COM addin?

Thanks,
John
Posted 27 May, 2024 13:48:28 Top
Andrei Smolin


Add-in Express team


Posts: 18965
Joined: 2006-05-11
The exception is in the COM add-in. I remember we had some other issue related to SetHostApplication; I believe that was in a subsequent Add-in Express version.

If this relates to embedding an Excel sheet or range, then you get this exception either at the add-in startup or when Excel closes. If at startup, you could disable your functionality if ExcelApp.UserControl returns False. Check if you can override the ADXAddinModule.OnHostApplicationInitialized method - it the host has passed the Application object to the add-in and it is now safe to use the ExcelApp property.Don't know what to do next, though.

Regards from Poland (GMT+2),

Andrei Smolin
Add-in Express Team Leader
Posted 27 May, 2024 14:10:01 Top