Exception for Android 10 when using EventToCommandBehavior
for iOS and UWP this works

Working Bevavior
Crash when loading assemblies
XamarinCommunityToolkit 1.0.0 Pre 3
Xamarin Forms 4.8 SR3
Android 10 SDK
Using other Package Xamarin.Forms.BehaviorsPack
@Agredo can you provide a small sample that reproduces the issue?
Description
Exception for Android 10 when using EventToCommandBehavior
for iOS and UWP this works
Steps to Reproduce
- Install Nuget XamarinCommunityToolkit Pre 3
- Use EventToCommandBehavior in Entry for Completed Command
Expected Behavior
Working Bevavior
Actual Behavior
Crash when loading assemblies
Basic Information
XamarinCommunityToolkit 1.0.0 Pre 3
Xamarin Forms 4.8 SR3
Android 10 SDKWorkaround
Using other Package Xamarin.Forms.BehaviorsPack
Yeah, the sample will be very helpful! 馃憤
@Agredo would you be able to try the new pre4 version and see if that fixes the issue?
If not, please provide a reproduction project showing this issue so we can get to fixing it. Thanks! :)
@jfversluis sorry I currently domt have much time. I will try it to reproduce it the next days
Sure thing, let us know! Thanks!
@Agredo did you manage to get a reproduction? Or try with the latest pre-release? :) Maybe we fixed it in the meanwhile
@jfversluis I can confirm this is broken and also still is with the 4th pre-release version. When setting the EventToCommandBehavior on a View, the Android app crashes in Release mode (it works properly in Debug mode, so no crash, but the Command execution also works properly). It even crashes on Android without having set the EventName property on the EventToCommandBehavior (so just plain adding this Behavior to a View). I've tried changing the linker settings, but that didn't made any difference (also didn't expect this to, but just wanted to be sure). I'll try to have another look at this tomorrow and hopefully solve this issue. And otherwise I'll share a reproduction project here 馃憣 !
Did you reference it in XAML only? Could you try adding a dummy reference in code, to completely rule out the linker? Because I still have a suspicion that has to do with it.
@jfversluis that didn't make any difference unfortunately. The logs are also pointing to a NullReferenceException inside the EventToCommandBehavior, so it's not the behavior reference that could not be found. The Exception occurs in EventToCommandBehavior.RegisterEvent() after the EventToCommandBehavior.OnAttached() is called.
Here are the logs:
2020-11-06 07:18:42.820 25029-25029/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.companyname.xct.eventtocommandandroidbug, PID: 25029
android.runtime.JavaProxyThrowable: System.NullReferenceException: Object reference not set to an instance of an object
at Xamarin.CommunityToolkit.Behaviors.EventToCommandBehavior.RegisterEvent () [0x0005b] in <2d63463870934a409d06bd6d670251a6>:0
at Xamarin.CommunityToolkit.Behaviors.EventToCommandBehavior.OnAttachedTo (Xamarin.Forms.View bindable) [0x00007] in <2d63463870934a409d06bd6d670251a6>:0
at Xamarin.Forms.Behavior`1[T].OnAttachedTo (Xamarin.Forms.BindableObject bindable) [0x00007] in <195b153c216c400ab511ea0b93c8af0b>:0
And this is the EventToCommandBehavior.RegisterEvent() code:
void RegisterEvent()
{
UnregisterEvent(); // the stack trace don't list this method, so it's not in here, right?!
var eventName = EventName;
if (View == null || string.IsNullOrWhiteSpace(eventName))
return; // when not setting the EventName at all, it still crashes, so the crash must be before this line of code, right?!
...
}
Just verified with attached repro. When you set it to release it crashes, but when you set Linker to Don't Link, it all works. So _something_ gets taken out. @pictos you are the linker expert by now? :D
Just checked iOS. Happens there too.
Looking closer at what @jBijsterboschNL posted earlier I see: at Xamarin.Forms.Behavior1[T].OnAttachedTo (Xamarin.Forms.BindableObject bindable) [0x00007] in <195b153c216c400ab511ea0b93c8af0b>:0`
It seems to happen in the BaseBehavior.OnAttachedTo? Possibly because of the reflection stuff going on in that class
@jfversluis I'll investigate this one (:
Yeah, it's a linker issue, and looks like that I found a solution for sure. I'll send a PR ASAP to solve this. Tks @jBijsterboschNL to take the time to create a reproduction sample <3.
Most helpful comment
Yeah, it's a linker issue, and looks like that I found a solution for sure. I'll send a PR ASAP to solve this. Tks @jBijsterboschNL to take the time to create a reproduction sample <3.