NetOfficeFw / NetOffice

🌌 Create add-ins and automation code for Microsoft Office applications.
MIT License
700 stars 145 forks source link

Can not add ClickEvent handler on CommandBarButton (v1.9.5) #414

Closed Berry68 closed 5 months ago

Berry68 commented 5 months ago

I'm trying to run the Excel Examples and I am facing a problem with Example09 when connecting to Microsoft Excel 365.

When a new CommandBarButton is added (either to a CommandBarPopup menu or a CommandBar) and the ClickEvent is about to be added, an Exception occurs with the following StackTrace:

   COMException: No such interface supported

   at System.Runtime.InteropServices.ComTypes.IConnectionPoint.Advise(Object pUnkSink, Int32& pdwCookie)
   at NetOffice.SinkHelper.SetupEventBinding(IConnectionPoint connectPoint)
   at NetOffice.OfficeApi.CommandBarButton.CreateEventBridge()
   at NetOffice.OfficeApi.CommandBarButton.add_ClickEvent(CommandBarButton_ClickEventHandler value)
   at ExcelExamplesCS4.Example09.buttonStartExample_Click(Object sender, EventArgs e) in C:\src\NetOffice\Examples\Excel\Standard Examples\ExcelExamples\Examples\Example09.cs:line 113
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.RunDialog(Form form)
   at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
   at ExampleBase.AreaForm.ShowForm(IWin32Window owner, IExample example)
   at ExampleBase.ExampleForm.ExamplesView_MouseDoubleClick(Object sender, MouseEventArgs e)
jozefizso commented 5 months ago

The Excel sample 09 works.

Microsoft® Excel® for Microsoft 365 MSO (Version 2407 Build 16.0.17730.20000) 32-bit

image

Berry68 commented 5 months ago

I've run the Excel sample 09 on a different laptop and it works. I've also tried running the same sample on 2 other laptops and on those laptops it still fails with the above mentioned Exception. All 3 laptops have Microsoft Office 365 (Version 2405 Build 17628.20110) and are running the exact same sample executable.

What could be causing the Exception? It happens when the code is adding the ClickEvent handler. If I remove this code then the sample is able to start Excel and adding the commandBarPopup's and commandBarButton.

jozefizso commented 5 months ago

In that case you must contact Microsoft Support to resolve issue with your Windows and/or Office.