New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error Implementing IDataWindow with RadWindow #1125

Closed
halbustami opened this Issue Oct 20, 2017 · 6 comments

Comments

Projects
None yet
2 participants
@halbustami

halbustami commented Oct 20, 2017

I realize I'm reposting this but the bug reappeared and I was able to reproduce it now.

IF BUG, INCLUDE THIS PART:

When attempting to use IUIVisualizerService to launch a radwindow the following error occurs:

00:17:01:840 => [DEBUG] [Catel.MVVM.TaskCommand`3] [1] Executing task command
WPFApplication1.exe Error: 0 : 00:17:01:845 => [ERROR] [Catel.MVVM.TaskCommand`3] [1] Task ended with exception | [ArgumentException] System.ArgumentException: Object of type 'System.EventHandler' cannot be converted to type 'System.EventHandler`1[Telerik.Windows.Controls.WindowClosedEventArgs]'.
   at System.RuntimeType.TryChangeType(Object value, Binder binder, CultureInfo culture, Boolean needsSpecialCast)
   at System.Reflection.MethodBase.CheckArguments(Object[] parameters, Binder binder, BindingFlags invokeAttr, CultureInfo culture, Signature sig)
   at System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Catel.Services.UIVisualizerService.HandleCloseSubscription(Object window, Object data, EventHandler`1 completedProc, Boolean isModal) in C:\CI_WS\Ws\105284\Source\Catel\src\Catel.MVVM\Catel.MVVM.Shared\Services\UIVisualizerService.wpf.cs:line 141
   at Catel.Services.UIVisualizerService.ShowWindowAsync(FrameworkElement window, Object data, Boolean showModal) in C:\CI_WS\Ws\105284\Source\Catel\src\Catel.MVVM\Catel.MVVM.Shared\Services\UIVisualizerService.wpf.cs:line 155
   at Catel.Services.UIVisualizerService.<ShowAsync>d__13.MoveNext() in C:\CI_WS\Ws\105284\Source\Catel\src\Catel.MVVM
\Catel.MVVM.Shared\Services\UIVisualizerService.cs:line 174
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Catel.Services.UIVisualizerService.<ShowAsync>d__12.MoveNext() in C:\CI_WS\Ws\105284\Source\Catel\src\Catel.MVVM\Catel.MVVM.Shared\Services\UIVisualizerService.cs:line 151
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at WPFApplication1.ViewModels.RibbonViewModel.<LaunchWindowCommand>d__2.MoveNext() in D:\Users\hayth\Documents\Visual Studio 2015\Projects\WPFApplication1\WPFApplication1\ViewModels\RibbonViewModel.cs:line 26
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Catel.MVVM.TaskCommand`3.<Execute>d__37.MoveNext() in C:\CI_WS\Ws\105284\Source\Catel\src\Catel.MVVM\Catel.MVVM.Shared\MVVM\Commands\TaskCommand.cs:line 269
An unhandled exception of type 'System.ArgumentException' occurred in mscorlib.dll
Object of type 'System.EventHandler' cannot be converted to type 'System.EventHandler`1[Telerik.Windows.Controls.WindowClosedEventArgs]'.

Steps to reproduce

  1. Launch the application
  2. Click on the button in the ribbon that will launch the model window

Platform:
.NET version: 4.6.1

Expected behaviour

Tell us what should happen

Actual behaviour

Tell us what happens instead
Can you also include a screen shot?
I've attached a repro of the problem

Repro.zip

@GeertvanHorrik GeertvanHorrik added the bug label Oct 22, 2017

@GeertvanHorrik

This comment has been minimized.

Show comment
Hide comment
@GeertvanHorrik

GeertvanHorrik Oct 22, 2017

Member

We need to check the event handler used by Telerik for the close event.

Member

GeertvanHorrik commented Oct 22, 2017

We need to check the event handler used by Telerik for the close event.

@GeertvanHorrik GeertvanHorrik added this to the 5.3.0 milestone Oct 22, 2017

@GeertvanHorrik GeertvanHorrik self-assigned this Oct 22, 2017

@GeertvanHorrik GeertvanHorrik modified the milestones: 5.3.0, 5.4.0 Jan 19, 2018

@halbustami

This comment has been minimized.

Show comment
Hide comment
@halbustami

halbustami Jan 22, 2018

Geert,

I took the liberty to look into this a little. Under the "HandleCloseSubscription(object window, object data, EventHandler completedProc, bool isModal)" method in the "UIVisualizerService" I changed the event handler to a generic to "EventHandler eventHandler = null;" just to test it out as you can see in the attached screenshot and it looks like this would work.
capture

However, this is not really a practical solution. Do you think that it would be worth passing those event arguments as optional parameters in the ShowAsync methods and modify the HandleCloseSubscription to handle those if not null? I have produced a better Repro if you'd like to see it.

halbustami commented Jan 22, 2018

Geert,

I took the liberty to look into this a little. Under the "HandleCloseSubscription(object window, object data, EventHandler completedProc, bool isModal)" method in the "UIVisualizerService" I changed the event handler to a generic to "EventHandler eventHandler = null;" just to test it out as you can see in the attached screenshot and it looks like this would work.
capture

However, this is not really a practical solution. Do you think that it would be worth passing those event arguments as optional parameters in the ShowAsync methods and modify the HandleCloseSubscription to handle those if not null? I have produced a better Repro if you'd like to see it.

@GeertvanHorrik

This comment has been minimized.

Show comment
Hide comment
@GeertvanHorrik

GeertvanHorrik Jan 22, 2018

Member

Thanks for the investigation. I don't believe we use the event args at all in that method. In that case it should be irrelevant, but I wasn't aware you could simply cast an EventHandler<T> to EventHandler. Does using EventHandler work in both Telerik and regular windows?

Member

GeertvanHorrik commented Jan 22, 2018

Thanks for the investigation. I don't believe we use the event args at all in that method. In that case it should be irrelevant, but I wasn't aware you could simply cast an EventHandler<T> to EventHandler. Does using EventHandler work in both Telerik and regular windows?

@halbustami

This comment has been minimized.

Show comment
Hide comment
@halbustami

halbustami Jan 23, 2018

I did some further fiddling with this. You are correct, you can't just simply cast to between EventHandler and EventHander<T> ; will have to get some reflection involved. Only practical solution I can think of right now is to just create a new class and inherit fromIUIVisualizerService and then override the HandleCloseSubscription method. I did some initial testing and it's working. If this proves to be practical then documenting the way to do it in your Catel documentation for Radwindows would be the way to go. I'll keep you posted.

halbustami commented Jan 23, 2018

I did some further fiddling with this. You are correct, you can't just simply cast to between EventHandler and EventHander<T> ; will have to get some reflection involved. Only practical solution I can think of right now is to just create a new class and inherit fromIUIVisualizerService and then override the HandleCloseSubscription method. I did some initial testing and it's working. If this proves to be practical then documenting the way to do it in your Catel documentation for Radwindows would be the way to go. I'll keep you posted.

@halbustami

This comment has been minimized.

Show comment
Hide comment
@halbustami

halbustami Jan 25, 2018

@GeertvanHorrik , Like I said above I think the simplest solution is just to update the documentation for Radwindow mentioned in http://docs.catelproject.com/5.2/catel-mvvm/views/xaml/external-controls/using-custom-window/ and show how to override the HandleCloseSubscription method. If not, then we would need to come up with some logic to cast the EventHandler to whatever EventHander<T> a window would use. What do you think? If you agree then this could be closed. I could help with the documentation if you don't have time.

halbustami commented Jan 25, 2018

@GeertvanHorrik , Like I said above I think the simplest solution is just to update the documentation for Radwindow mentioned in http://docs.catelproject.com/5.2/catel-mvvm/views/xaml/external-controls/using-custom-window/ and show how to override the HandleCloseSubscription method. If not, then we would need to come up with some logic to cast the EventHandler to whatever EventHander<T> a window would use. What do you think? If you agree then this could be closed. I could help with the documentation if you don't have time.

@GeertvanHorrik

This comment has been minimized.

Show comment
Hide comment
@GeertvanHorrik

GeertvanHorrik Jan 25, 2018

Member

@halbustami I think you are right, we shouldn't be modifying the code just because of some 3rd party fx. Would love to see the docs updated with a PR, thanks in advance!

Member

GeertvanHorrik commented Jan 25, 2018

@halbustami I think you are right, we shouldn't be modifying the code just because of some 3rd party fx. Would love to see the docs updated with a PR, thanks in advance!

@GeertvanHorrik GeertvanHorrik removed this from the 5.4.0 milestone Jan 25, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment