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
- fix #2866 Changed ObserveOn to only affect the internal subscription — committed to reactiveui/ReactiveUI by ChrisPulman 3 years ago
- fix #2866 CanExecute Scheduler (#2880) — committed to reactiveui/ReactiveUI by ChrisPulman 3 years ago
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
ReactiveUIversion. One is usingReactiveUI 14.1.1, the otherReactive UI 14.3.1The testing code is as follow:
The command is successfully executed when using
ReactiveUI 14.1.1, but is not executed with the latestReactiveUIversion.I hope that can help.
I’ve used
.net 4.7.2console 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:
My android project is setup to target Android 10. I’ve tested my app on an Android device running Android 11.
I’ve tested my app on an iPhone 12 device running iOS 14.5.
–> Same result as the console application projects.
InvokeCommandextension method works fine up toReactiveUI 14.1.1when used in conjunction withObservable.Return(...), but doesn’t work with the latest version.Thank you for the added information, I will investigate this evening.
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.
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.