While I can definitely reproduce this bug...it's a repetitive process and when it happens appears to be inconsistent as far as I can tell.
It would be a bit more bearable if it consistently failed many MANY repetitions in, but in my actual app that has more pages with ListViews, it sometimes fails very quickly.
I've only been able to test this on an HTC One M8 with Android 4.4.4...I haven't tried to reproduce this in an emulator yet.
I've attached a zip with a simple project that can reproduce the problem and following are the steps to reproduce it.
- Tap the first button on the main page
- Tap several items in list 1 to change the switch's value
- Go back to main screen
- Tap the second button on the main screen
- Tap several items in list 2 to change the switch's value
- Go back to main screen
- Repeat 1-6 until you get the exception
It will fail inside one of the two models (depending on which list has the error) within the RaisePropertyChanged method on the call to PropertyChanged.
Here's the full exception:
System.ArgumentException: 'jobject' must not be IntPtr.Zero.
Parameter name: jobject
at Android.Runtime.JNIEnv.CallVoidMethod (intptr,intptr,Android.Runtime.JValue[]) [0x00010] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.18-series/3b7ef0a7/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:500
at Android.Widget.CompoundButton.set_Checked (bool) [0x00043] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.18-series/3b7ef0a7/source/monodroid/src/Mono.Android/platforms/android-19/src/generated/Android.Widget.CompoundButton.cs:274
at Xamarin.Forms.Platform.Android.SwitchRenderer.HandleToggled (object,System.EventArgs) <IL 0x00011, 0x000b7>
at Xamarin.Forms.Switch.<.cctor>b__0 (Xamarin.Forms.BindableObject,object,object) <IL 0x0001c, 0x00123>
at Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty,object,bool,bool,bool) <IL 0x000b9, 0x0058f>
at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty,object,bool,bool,bool) <IL 0x00213, 0x00aeb>
at Xamarin.Forms.BindingExpression.ApplyCore (object,Xamarin.Forms.BindableObject,Xamarin.Forms.BindableProperty,bool) <IL 0x00206, 0x01287>
at Xamarin.Forms.BindingExpression.Apply (bool) <IL 0x00041, 0x0018b>
at Xamarin.Forms.BindingExpression/BindingExpressionPart.<PropertyChanged>b__12 () <IL 0x00007, 0x00053>
at Java.Lang.Thread/RunnableImplementor.Run () [0x0000b] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.18-series/3b7ef0a7/source/monodroid/src/Mono.Android/src/Java.Lang/Thread.cs:36
at Java.Lang.IRunnableInvoker.n_Run (intptr,intptr) [0x00009] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.18-series/3b7ef0a7/source/monodroid/src/Mono.Android/platforms/android-19/src/generated/Java.Lang.IRunnable.cs:71
at (wrapper dynamic-method) object.6522ff35-60f0-4960-914c-627b776c78b2 (intptr,intptr) <IL 0x00011, 0x0003b>
Is there a way to work around this problem?
Thanks