Bug 56274 - Cell calling Command.ChangeCanExecute in ContextAction chrashes
Summary: Cell calling Command.ChangeCanExecute in ContextAction chrashes
Status: RESOLVED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Android ()
Version: 2.3.5
Hardware: PC Windows
: Normal critical
Target Milestone: ---
Assignee: Bugzilla
URL:
: 59580 ()
Depends on:
Blocks:
 
Reported: 2017-05-12 09:41 UTC by Dániel Buga
Modified: 2017-09-21 11:11 UTC (History)
6 users (show)

Tags: android contextaction command ac fr
Is this bug a regression?: No
Last known good build:


Attachments
Page files (.xaml, .cs) (1.04 KB, application/x-zip-compressed)
2017-05-12 09:41 UTC, Dániel Buga
Details
repro project (296.42 KB, application/x-zip-compressed)
2017-05-13 00:10 UTC, Jimmy [MSFT]
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Dániel Buga 2017-05-12 09:41:31 UTC
Created attachment 22112 [details]
Page files (.xaml, .cs)

The attached example page crashes on my android tablet when I invoke a context action on one of the list items.

Exception:
System.NullReferenceException: Object reference not set to an instance of an object.

  at Xamarin.Forms.Platform.Android.CellAdapter.OnContextActionCommandCanExecuteChanged (System.Object sender, System.EventArgs eventArgs) <0x572cebb8 + 0x0006c> in <e988034fb3594297a41068007e97ab2b>:0 
  at (wrapper delegate-invoke) <Module>:invoke_void_object_EventArgs (object,System.EventArgs)
  at Xamarin.Forms.Command.ChangeCanExecute () [0x00006] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\Command.cs:113 
  at MyApp.Views.ViewCellContextCommandTestPage.<.ctor>b__5_0 () [0x00001] in <project>\Views\ViewCellContextCommandTestPage.xaml.cs:30 
  at Xamarin.Forms.Command+<>c__DisplayClass5_0.<.ctor>b__0 (System.Object o) [0x00000] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\Command.cs:87 
  at Xamarin.Forms.Command.Execute (System.Object parameter) [0x00000] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\Command.cs:107 
  at Xamarin.Forms.MenuItem.Activate () [0x00010] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\MenuItem.cs:90 
  at Xamarin.Forms.Platform.Android.CellAdapter.OnActionItemClickedImpl (Android.Views.IMenuItem item) [0x00000] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\AppCompat\FormsAppCompatActivity.cs:60 
  at Xamarin.Forms.Platform.Android.CellAdapter.global::Android.Support.V7.View.ActionMode.ICallback.OnActionItemClicked (Android.Support.V7.View.ActionMode mode, Android.Views.IMenuItem item) [0x00000] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\Cells\EntryCellView.cs:129 
  at Android.Support.V7.View.ActionMode+ICallbackInvoker.n_OnActionItemClicked_Landroid_support_v7_view_ActionMode_Landroid_view_MenuItem_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_mode, System.IntPtr native_item) [0x00019] in <c690702816034f28aca512af1f0abd66>:0 
  at (wrapper dynamic-method) System.Object:b3afb882-c7a3-4782-8834-0cb9a16833fb (intptr,intptr,intptr,intptr)
Comment 1 Jimmy [MSFT] 2017-05-13 00:10:18 UTC
Created attachment 22154 [details]
repro project

I used the layout files provided in a new project and I am able to reproduce this crash. I've attached the project and I am confirming this report so the team can investigate further.

Other lines of code in the command action that are called before ChangeCanExecute() run fine, so it's just when calling ChangeCanExecute() itself that it crashes.

This is only affecting Android, the crash does _not_ occur on UWP or iOS. 


### Version tests
2.3.6.98    BAD
2.3.5-pre3  BAD
2.3.4.231   BAD
2.3.3.193   BAD
Comment 2 Dániel Buga 2017-08-14 10:09:58 UTC
So, 3 months have passed and my app is still hit by this issue, that is marked CONFIRMED and critical. I hate to ask this, but has this issue been forgotten?
Comment 3 HRO Jordy 2017-08-24 14:26:35 UTC
We also encounter this issue. 

Xamarin Forms version v2.3.5.256-pre6
Crashes on both Android and iOS

Any ETA when this will be fixed, or a possible workaround?

ANDROID callstack:

--Object reference not set to an instance of an object

CellAdapter.OnContextActionCommandCanExecuteChanged (System.Object sender, System.EventArgs eventArgs)
(wrapper delegate-invoke) :invoke_void_object_EventArgs (object,System.EventArgs)
Command.ChangeCanExecute ()
ContactsViewModel+<ExecuteContactRemoved>d__26.MoveNext ()
ExceptionDispatchInfo.Throw ()
TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task)
TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task)
TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task)
TaskAwaiter.GetResult ()
ContactsViewModel+<<get_ContactRemovedCommand>b__25_0>d.MoveNext ()
ExceptionDispatchInfo.Throw ()
AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_0 (System.Object state)
SyncContext+<>c__DisplayClass2_0.<Post>b__0 ()
Thread+RunnableImplementor.Run ()
IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this)
(wrapper dynamic-method) System.Object:d7543e26-428d-4a91-b471-8591a1d60d79 (intptr,intptr)



iOS Callstack:

--Object reference not set to an instance of an object

ContextActionsCell.OnMenuItemPropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs e)
BindableObject.OnPropertyChanged (System.String propertyName)
Element.OnPropertyChanged (System.String propertyName)
BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindableObject+BindablePropertyContext context, System.Object value, System.Boolean currentlyApplying, Xamarin.Forms.Internals.SetValueFlags attributes, System.Boolean silent)
BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes)
BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value, System.Boolean fromStyle, System.Boolean checkAccess)
BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value)
BindableObject.set_BindingContext (System.Object value)
ExtendedViewCell.OnBindingContextChanged ()
BindableObject.BindingContextPropertyChanged (Xamarin.Forms.BindableObject bindable, System.Object oldvalue, System.Object newvalue)
BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindableObject+BindablePropertyContext context, System.Object value, System.Boolean currentlyApplying, Xamarin.Forms.Internals.SetValueFlags attributes, System.Boolean silent)
BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes)
BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value, System.Boolean fromStyle, System.Boolean checkAccess)
BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value)
BindableObject.set_BindingContext (System.Object value)
TemplatedItemsList`2+<UnhookItem>d__153[TView,TItem].MoveNext ()
ExceptionDispatchInfo.Throw ()
AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_0 (System.Object state)
UIKitSynchronizationContext+<Post>c__AnonStorey0.<>m__0 ()
NSAsyncActionDispatcher.Apply ()
(wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate)
UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName)
Application.Main (System.String[] args)
Comment 4 HRO Jordy 2017-09-07 13:20:01 UTC
See also: https://bugzilla.xamarin.com/show_bug.cgi?id=33413
Comment 5 Samantha Houts [MSFT] 2017-09-19 17:21:05 UTC
https://github.com/xamarin/Xamarin.Forms/pull/1147
Comment 6 Samantha Houts [MSFT] 2017-09-19 17:22:09 UTC
*** Bug 59580 has been marked as a duplicate of this bug. ***
Comment 7 Rui Marinho 2017-09-21 11:11:18 UTC
Should be fixed on 2.4.1-pre1