You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I develop an Excel add-in which uses NetOffice to interact with Excel via COM. I am currently trying to upgrade from v1.7.4.4 to v1.9.7.
Having fixed the majority of breaking changes, I am left with one aspect of unexplained behaviour.
Previously, using NetOffice v1.7.4.4, I was trapping Excel's WindowActivateEvent, using a handler with code like this (simplified):
private void OnWindowActivate(Excel.Workbook workbook, Excel.Window window)
{
using (workbook)
using (window)
{
if (!return this.isSdiInterface)
{
// Not supported.
return;
}
var windowHandle = window.Hwnd;
// Do something with the window handle.
}
});
The primary use case is to register a custom task pane in the window when a new or existing workbook is first opened. I don't recall this ever failing.
However, after upgrading to NetOffice 1.9.7, I find that window.Hwnd always throws an exception in this scenario:
NetOffice.Exceptions.PropertyGetCOMException (0x80004005): Failed to proceed PropertyGet on Excel.Window=>Hwnd.
--->
System.Runtime.InteropServices.COMException (0x80020006): Unknown name. (Exception from HRESULT: 0x80020006 (DISP_E_UNKNOWNNAME))
Is this expected?
Is there a straightforward fix which would revert the behaviour?
Could anybody point me to the area of the NetOffice code that has changed, e.g. the relevant branch / pull request / changeset?
It seems that I might be able to achieve what I need by instead trapping the WorkbookActivateEvent and using the following:
private void OnWorkbookActivate(Excel.Workbook workbook)
{
using (workbook)
using (var window = workbook.Application.ActiveWindow)
{
var windowHandle = window.Hwnd;
}
}
However, I am loath to make this change, especially without understanding it, unless absolutely essential, because the previous implementation was extremely stable and it will be challenging for me to test the change in a wide variety of environments to ensure that it works reliably. In particular, I am concerned about a race condition with workbook.Application.ActiveWindow (because the active window might have changed since the event handler was triggered).
I am using .NET Framework 4.8 and Microsoft Excel 365 MSO (Version 2503 Build 16.0.18623.20208) 64-bit.
Thanks in advance to anyone who can point me in the right direction here.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I develop an Excel add-in which uses NetOffice to interact with Excel via COM. I am currently trying to upgrade from v1.7.4.4 to v1.9.7.
Having fixed the majority of breaking changes, I am left with one aspect of unexplained behaviour.
Previously, using NetOffice v1.7.4.4, I was trapping Excel's
WindowActivateEvent, using a handler with code like this (simplified):The primary use case is to register a custom task pane in the window when a new or existing workbook is first opened. I don't recall this ever failing.
However, after upgrading to NetOffice 1.9.7, I find that
window.Hwndalways throws an exception in this scenario:It seems that I might be able to achieve what I need by instead trapping the
WorkbookActivateEventand using the following:However, I am loath to make this change, especially without understanding it, unless absolutely essential, because the previous implementation was extremely stable and it will be challenging for me to test the change in a wide variety of environments to ensure that it works reliably. In particular, I am concerned about a race condition with
workbook.Application.ActiveWindow(because the active window might have changed since the event handler was triggered).I am using .NET Framework 4.8 and Microsoft Excel 365 MSO (Version 2503 Build 16.0.18623.20208) 64-bit.
Thanks in advance to anyone who can point me in the right direction here.
Beta Was this translation helpful? Give feedback.
All reactions