NetOfficeFw / NetOffice

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

ActivePowerPointApp.SlideShowBeginEvent doesn't work in versions 1.7.4.x #262

Closed DominikPalo closed 4 years ago

DominikPalo commented 4 years ago

I've just updated the NuGet package form version 1.7.3.1 to the latest version - 1.7.4.6 and the event ActivePowerPointApp.SlideShowBeginEvent is no longer fired when the PowerPoint switches to the SlideShow mode. Other events, like ActivePowerPointApp.WindowActivateEvent, ActivePowerPointApp.SlideShowEndEvent work as expected. I also tried the version 1.7.4.1 with no success - the last version where this event was working was 1.7.3.1.

jozefizso commented 4 years ago

EApplication.SlideShowBegin() method handles the PowerPoint event SlideShowBegin and invokes the event handler method in user code.

https://github.com/NetOfficeFw/NetOffice/blob/3b56a7420dab2d1a18d4b60ae8e12e728423cf1b/Source/PowerPoint/Events/EApplication.cs#L372-L384

SlideShowBegin event has single parameter of type SlideShowWindow.

This is incorrectly defined in NetOffice code as parameter of type DocumentWindow. Because of this type mismatch, there is internal exception and the event handler is not fired.

System.ArgumentException: 'Object of type 'NetOffice.PowerPointApi.DocumentWindow' cannot be converted to type 'NetOffice.PowerPointApi.SlideShowWindow'.'

 mscorlib.dll!System.RuntimeType.TryChangeType(object value, System.Reflection.Binder binder, System.Globalization.CultureInfo culture, bool needsSpecialCast)
 mscorlib.dll!System.RuntimeType.CheckValue(object value, System.Reflection.Binder binder, System.Globalization.CultureInfo culture, System.Reflection.BindingFlags invokeAttr)
 mscorlib.dll!System.Reflection.MethodBase.CheckArguments(object[] parameters, System.Reflection.Binder binder, System.Reflection.BindingFlags invokeAttr, System.Globalization.CultureInfo culture, System.Signature sig)

 Line 126 : > NetOffice.dll!NetOffice.Events.CoClassEventReflector.RaiseCustomEvent(NetOffice.ICOMObject instance, System.Type type, string eventName, ref object[] paramsArray)
 Line 1108:   PowerPointApi.dll!NetOffice.PowerPointApi.Application.RaiseCustomEvent(string eventName, ref object[] paramsArray)
 Line 383:    PowerPointApi.dll!NetOffice.PowerPointApi.Events.EApplication_SinkHelper.SlideShowBegin(object wn)

Untitled_Clipping_032120_045123_PM

jozefizso commented 4 years ago

Should be fixed in 1.7.4.7

https://www.nuget.org/packages/NetOfficeFw.PowerPoint/1.7.4.7

DominikPalo commented 4 years ago

Thanks for fixing, I've just tried the version 1.7.4.7 - the SlideShowBeginEvent is firing, but there is another issue: The SlideshowWindow parameter passed to the SlideShowBeginEvent and SlideShowNextSlideEvent is now null (was ok in 1.7.3.1)

image

image

DominikPalo commented 4 years ago

I found the problem, here is the fix https://github.com/NetOfficeFw/NetOffice/pull/266

jozefizso commented 4 years ago

Yeah, I am sorry I missed that. I checked the event was firing and I forget to check the parameters.

jozefizso commented 4 years ago

Try the 1.7.4.8

jozefizso commented 4 years ago

I added unit tests for SlideShowBegin, SlideShowNextBuild and SlideShowNextSlide to make sure the objects passed to the event handlers are correct.