ReactiveUI: [BUG] InvokeCommand doesn't invoke command

I upgraded to latest version (from 14.1.1 to 14.2.1) and, suddenly, InvokeCommand from an observable stopped to invoke my command. Command espects an Unit (in this context) as input, but command invocation is ignored. If I force to invoke manually that command, it executes correctly, but not via binding. Command doesn’t have any validation for CanExecute or nothing.

Steps To Reproduce 1 - Command creation:

this.InitializeCommand = ReactiveCommand.CreateFromObservable<TInput, Unit>(
                inputCmd =>
                {
                    // Never enters via InvokeCommand, but enters when Execute call method is used.
                    return Observable.FromAsync(
                                          async ct =>
                                          {
                                              .....
                                          })
                                     .TakeUntil(this.CancelInitializeCommand);

                });

2 - Binding initialization:

this.WhenAnyValue(vm => vm.Input)
      // .Do(_ => Debug.WriteLine("Arrives?") --> YES, it arrives
      .WhereNotNull()
      // .Do(_ => Debug.WriteLine("Arrives?") --> YES, it arrives
      .DistinctUntilChanged()
      // .Do(_ => Debug.WriteLine("Arrives?") --> YES, it arrives
      .InvokeCommand(this.InitializeCommand) // Does nothing
      .DisposeWith(d);

Expected behavior Command is called on InvokeCommand.

Environment

  • OS: Windows 10
  • Version 21H1
  • Device: PC
  • Application Type: WinForms Application
  • SDK: .NET Framework 4.7.2

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 24 (12 by maintainers)

Commits related to this issue

Most upvoted comments

Issues is solved for me. Thank you very much.

I am also facing the same issue.

I’ve created a simple solution with two console projects. https://github.com/EmilienDup/ReactiveUI_bug_report_14.3.1_InvokeCommand The code and runtime configuration are the same for the two projects.

The only difference is the ReactiveUI version. One is using ReactiveUI 14.1.1, the other Reactive UI 14.3.1

The testing code is as follow:

public static async Task Main(string[] args)
{
	var semaphore = new SemaphoreSlim(0);
	var command = ReactiveCommand.Create(() =>
	{
		semaphore.Release();
	});

	Observable.Return(Unit.Default)
                           .InvokeCommand(command);

	var task = semaphore.WaitAsync();
	if (await Task.WhenAny(Task.Delay(TimeSpan.FromMilliseconds(100)), task) == task)
	{
		System.Diagnostics.Debug.WriteLine("Command executed");
	}
	else
	{
		System.Diagnostics.Debug.WriteLine("Command not executed");
	}
}

The command is successfully executed when using ReactiveUI 14.1.1, but is not executed with the latest ReactiveUI version.

I hope that can help.

<div> GitHub</div><div>GitHub - EmilienDup/ReactiveUI_bug_report_14.3.1_InvokeCommand: ReactiveUI Bug Report [14.3.1] InvokeCommand extension method</div><div>ReactiveUI Bug Report [14.3.1] InvokeCommand extension method - GitHub - EmilienDup/ReactiveUI_bug_report_14.3.1_InvokeCommand: ReactiveUI Bug Report [14.3.1] InvokeCommand extension method</div>

Seems very platform specific

I’ve used .net 4.7.2 console application in my testing project as I thought it may be easier for you guys to investigate 😉

But I’ve first experienced this problem on both Xamarin.Android and Xamarin.iOS applications.

I’ve added Xamarin.Forms testing projects to my repo. The code that is executed is a bit different from the console app projects, but it should demonstrates that the problem exists on those platforms as well.

Here are some details about my setup, just in case:

Visual Studio Community 2019 for Mac
Version 8.10.6 (build 10)
Xamarin.Android
Version: 11.3.0.4 (Visual Studio Community)
Commit: xamarin-android/d16-10/ae14caf
Android SDK: /Users/emilien/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		6.0 (API level 23)
		7.1 (API level 25)
		8.1 (API level 27)

SDK Tools Version: 26.1.1
SDK Platform Tools Version: 31.0.0
SDK Build Tools Version: 29.0.2

My android project is setup to target Android 10. I’ve tested my app on an Android device running Android 11.

Xamarin.iOS
Version: 14.20.0.24 (Visual Studio Community)
Hash: c4b89cddb
Branch: d16-10
Build date: 2021-06-15 22:03:01-0400

I’ve tested my app on an iPhone 12 device running iOS 14.5.

–> Same result as the console application projects. InvokeCommand extension method works fine up to ReactiveUI 14.1.1 when used in conjunction with Observable.Return(...), but doesn’t work with the latest version.

Thank you for the added information, I will investigate this evening. image

I’ll get @ChrisPulman to chase this one down. Seems very platform specific.

Will adapt your code into a unit test most likely under our winforms tests and go from there.

image As far as I can replicate the code, this is working in the latest version 14.3.1

We are facing the same situation on our end. However, I’m guessing that the problem with InovkeCommand is just a symptom of some other issue. It looks like the initial value of the CanExecute property is always set to false, regardless of the actual logic which should be used for determining the CanExecute value.