Excel Addin Error In AddinExpress.XL.2005.dll

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

Excel Addin Error In AddinExpress.XL.2005.dll
Calling Show 
Michael Thrift




Posts: 41
Joined: 2015-06-09
We recently upgraded our Excel Addin from using Addin Express 8.2.4371.2005 to 9.4.4644.0

We made this upgrade to keep up with the DPI Compatibility issues on Windows 10 and the Windows 10 upgrade that causes the keyboard hook issue.

Anyway, I am able to build and register the project without any errors. But when debugging I get:


An unhandled exception of type 'System.NullReferenceException' occurred in AddinExpress.XL.2005.dll

Additional information: Object reference not set to an instance of an object.


This occurs when I call a Show() or ShowDialog() on a custom form. Often times I'm marshalling this back on the main thread. The error occurs at:


 	AddinExpress.XL.2005.dll!AddinExpress.XL.ADXExcelTaskPanesManager.OnHookHostEraseBackground(System.IntPtr hwndHost, System.IntPtr hdc)	Unknown
 	AddinExpress.XL.2005.dll!AddinExpress.Extensions.ADXCustomHostHook.DoHostEraseBackground(System.IntPtr hwndHost, System.IntPtr hdc)	Unknown
 	AddinExpress.XL.2005.dll!AddinExpress.Extensions.ADXXLMessageHook.DefaultHandler(bool currentThread, ref AddinExpress.Extensions.WindowsAPI.CWPSTRUCT msg)	Unknown
 	AddinExpress.XL.2005.dll!AddinExpress.Extensions.ADXMessageHook.CallbackFunction(int code, System.IntPtr wParam, System.IntPtr lParam)	Unknown
 	[Native to Managed Transition]	
 	[Managed to Native Transition]	
 	AddinExpress.MSO.2005.dll!AddinExpress.MSO.ADXAddinModule.ThreadHookProc(int nCode, System.IntPtr wParam, System.IntPtr lParam)	Unknown
 	[Native to Managed Transition]	
 	[Managed to Native Transition]	
 	PresentationFramework.dll!System.Windows.Window.ShowHelper(object booleanBox)	Unknown
 	PresentationFramework.dll!System.Windows.Window.Show()	Unknown
 	PresentationFramework.dll!System.Windows.Window.ShowDialog()	Unknown


I am using the Dispatcher.Invoke method to display the form.
Posted 12 Sep, 2019 11:10:18 Top
Michael Thrift




Posts: 41
Joined: 2015-06-09
To help, I also was able to get the same exception simply by closing the Document Recovery panel in Excel. As soon as I closed it, the same NullReference Exception was thrown in AddinExpress.XL.2005.dll.

The Addin loaded without error, but when closing the Document Recover panel, the below code was executed and errored. None of my own code ran.


>	AddinExpress.XL.2005.dll!AddinExpress.XL.ADXExcelTaskPanesManager.OnHookHostEraseBackground(System.IntPtr hwndHost, System.IntPtr hdc)	Unknown
 	AddinExpress.XL.2005.dll!AddinExpress.Extensions.ADXCustomHostHook.DoHostEraseBackground(System.IntPtr hwndHost, System.IntPtr hdc)	Unknown
 	AddinExpress.XL.2005.dll!AddinExpress.Extensions.ADXXLMessageHook.DefaultHandler(bool currentThread, ref AddinExpress.Extensions.WindowsAPI.CWPSTRUCT msg)	Unknown
 	AddinExpress.XL.2005.dll!AddinExpress.Extensions.ADXMessageHook.CallbackFunction(int code, System.IntPtr wParam, System.IntPtr lParam)	Unknown
 	[Native to Managed Transition]	
 	[Managed to Native Transition]	
 	AddinExpress.MSO.2005.dll!AddinExpress.MSO.ADXAddinModule.ThreadHookProc(int nCode, System.IntPtr wParam, System.IntPtr lParam)	Unknown
 	[AppDomain Transition]	
Posted 12 Sep, 2019 11:19:29 Top
Michael Thrift




Posts: 41
Joined: 2015-06-09
The newer version of Addin Express introduces a new Excel event hook:


_excelHook.HostEraseBackground += OnHookHostEraseBackground


When this event fires it loops through TaskPaneInstances in each of the ADXExcelTaskPanes in the Items collection. But i don't think it handles the possibility of the ADXExcelTaskPane object being null.

On the AddinStartUpComplete event we create a new ADXExcelTaskPanesCollectionItem as a placeholder. It is not visible initially, and is used to host different task panes based on users selecting different "Apps".

But because this is getting created at the onset, the OnHookHostEraseBackground method is finding this and the error is thrown when it doesn't find a TaskPane.
Posted 12 Sep, 2019 12:22:09 Top
Michael Thrift




Posts: 41
Joined: 2015-06-09
I was able to debug the code. The original code that errors:


foreach (ADXExcelTaskPane pane in item.TaskPaneInstances)
                    {
                        if (pane.Injected && pane.HostHandle == hwndHost)
                        {
                            ADXContainerControl container = pane.ContainerControl;
                            if (container != null)
                            {
                                Graphics dc = Graphics.FromHdc(hdc);
                                SolidBrush br = new SolidBrush(container.BackColor);
                                WindowsAPI.WINDOWPOS wpos = container.ScreenPos;
                                dc.FillRectangle(br, wpos.x, wpos.y, wpos.cx, wpos.cy);
                                br.Dispose();
                                dc.Dispose();
                            }
                        }
                    }


I simply added a null check on TaskPaneInstances and my addin worked as expected. Can you verify this is a defect?


if (item.TaskPaneInstances !=null)
                {

                    foreach (ADXExcelTaskPane pane in item.TaskPaneInstances)
                    {
                        if (pane.Injected && pane.HostHandle == hwndHost)
                        {
                            ADXContainerControl container = pane.ContainerControl;
                            if (container != null)
                            {
                                Graphics dc = Graphics.FromHdc(hdc);
                                SolidBrush br = new SolidBrush(container.BackColor);
                                WindowsAPI.WINDOWPOS wpos = container.ScreenPos;
                                dc.FillRectangle(br, wpos.x, wpos.y, wpos.cx, wpos.cy);
                                br.Dispose();
                                dc.Dispose();
                            }
                        }
                    }
                }
Posted 12 Sep, 2019 13:16:36 Top
Alexander Solomenko


Add-in Express team


Posts: 134
Joined: 2009-02-27
Hi Michael,

Thank you for your cooperation. This is our mistake indeed. We have already made corrections, and they will be included into the next release. If you need the updated assemblies, I can send them to you.
Regards,
Aleksandr Solomenko
Posted 13 Sep, 2019 03:28:44 Top
Michael Thrift




Posts: 41
Joined: 2015-06-09
Alexander - can you confirm that this issue would be on other events as well, such as OnHookDPIChanged? Does your fix include handling null reference on that event?

We are seeing a similar crash now when user's resize their window. We expect this is causing the DPI change event to fire.

If the updated assembly has this fix in place, I wouldn't mind having a copy of it. I may not be aware of all places you have made a correction.
Posted 16 Sep, 2019 13:09:03 Top
Andrei Smolin


Add-in Express team


Posts: 16808
Joined: 2006-05-11
Hello Michael,

I've sent you an email containing a download link and instruction describing how to install the assembly(ies) providing the fix.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 17 Sep, 2019 10:19:41 Top