Bug 43782 - "Animators may only be run on Looper threads" when raising ChangeCanExecute on Button command
Summary: "Animators may only be run on Looper threads" when raising ChangeCanExecute o...
Status: CONFIRMED
Alias: None
Product: Forms
Classification: Xamarin
Component: Android ()
Version: 2.3.1
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-08-26 08:42 UTC by Rogier van der Hee
Modified: 2017-07-13 20:56 UTC (History)
5 users (show)

Tags: ac
Is this bug a regression?: ---
Last known good build:

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 for Bug 43782 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
CONFIRMED

Description Rogier van der Hee 2016-08-26 08:42:03 UTC
I have a view model with a command for a button. When I raise ChangeCanExecute method on Command the button flips from enabled to disabled, but I got a main thread exception.

I think the renderer should ensure things are done on the main thread, as that is touching the View element and it should not be the responsibility of the view model, IMHO.


System.Diagnostics.Debugger.Mono_UnhandledException_internal() in 
System.Diagnostics.Debugger.Mono_UnhandledException(Android.Util.AndroidRuntimeException ex) in /Users/builder/data/lanes/3540/1cf254db/source/mono/mcs/class/corlib/System.Diagnostics/Debugger.cs:122
object.d54b8c39-4cf2-4565-8178-571c704bce52( arg0,  arg1,  arg2,  arg3) in 
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143
Java.Interop.JniEnvironment.InstanceMethods.CallVoidMethod(Java.Interop.JniObjectReference instance, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) in /Users/builder/data/lanes/3540/1cf254db/source/Java.Interop/src/Java.Interop/Java.Interop/JniEnvironment.g.cs:11643
Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeVirtualVoidMethod(string encodedMember, Android.Support.V7.Widget.AppCompatButton self, Java.Interop.JniArgumentValue* parameters) in /Users/builder/data/lanes/3540/1cf254db/source/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods_Invoke.cs:26
Android.Views.View.set_Enabled(bool value) in /Users/builder/data/lanes/3540/1cf254db/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Android.Views.View.cs:5198
Xamarin.Forms.Platform.Android.AppCompat.ButtonRenderer.UpdateEnabled() in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Platform.Android\AppCompat\ButtonRenderer.cs:234
Xamarin.Forms.Platform.Android.AppCompat.ButtonRenderer.OnElementPropertyChanged(Xamarin.Forms.Button sender, System.ComponentModel.PropertyChangedEventArgs e) in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Platform.Android\AppCompat\ButtonRenderer.cs:113
Xamarin.Forms.BindableObject.OnPropertyChanged(string propertyName) in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\BindableObject.cs:137
Xamarin.Forms.Element.OnPropertyChanged(string propertyName) in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\Element.cs:369
Xamarin.Forms.BindableObject.SetValueActual(Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindableObject.BindablePropertyContext context, bool value, bool currentlyApplying, Xamarin.Forms.BindableObject.SetValueFlags attributes, bool silent) in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\BindableObject.cs:581
Xamarin.Forms.BindableObject.SetValueCore(Xamarin.Forms.BindableProperty property, bool value, Xamarin.Forms.BindableObject.SetValueFlags attributes, Xamarin.Forms.BindableObject.SetValuePrivateFlags privateAttributes) in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\BindableObject.cs:378
Xamarin.Forms.BindableObject.SetValueCore(Xamarin.Forms.BindableProperty property, bool value, Xamarin.Forms.BindableObject.SetValueFlags attributes) in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\BindableObject.cs:324
Xamarin.Forms.Button.set_IsEnabledCore(bool value) in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\Button.cs:112
Xamarin.Forms.Button.CommandCanExecuteChanged(Xamarin.Forms.Command sender, System.EventArgs eventArgs) in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\Button.cs:172
Xamarin.Forms.Command.ChangeCanExecute() in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\Command.cs:77
Comment 1 Chris King 2016-10-05 18:22:44 UTC
Per Jason's feedback.
Comment 2 adrianknight89 2016-11-02 06:51:59 UTC
Can you attach a repro?
Comment 3 EB 2017-07-13 20:56:28 UTC
This is still an issue in the latest Xamarin Forms, and completely legitimate case to have this executed outside the main thread (i.e. when an event is fired such as a Bluetooth Device Disconnecting).

A work-a-round is to overide the PropertyChanged function in the renderer and execute the base function on the Main Thread, but you have to do this for every control that may have a Command binded to it.