Question

I am trying to get a simple skeleton ViewModel set up with ReactiveUI 6 (beta) and keep getting compiler errors (in Xamarin Studio, FWIW).

Code:

using System;
using System.Reactive;
using System.Reactive.Linq;
using ReactiveUI;

// ...

public IReactiveCommand TryAuthenticateCommand { get; protected set; }

// ...

this.TryAuthenticateCommand = ReactiveCommand.Create(
this.WhenAny(
    x => x.Username,
    x => x.Password,
    (username, password) => 
        !string.IsNullOrWhiteSpace(username.Value) && 
        !string.IsNullOrWhiteSpace(password.Value)));
this.TryAuthenticateCommand.Subscribe(x => MessageBus.Current.SendMessage("Yes!"));

Error:

Error CS0411: The type arguments for method `System.ObservableExtensions.Subscribe<T>(this System.IObservable<T>, System.Action<T>)' cannot be inferred from the usage. Try specifying the type arguments explicitly (CS0411)
Was it helpful?

Solution

This code is perfect, i think you're just missing a using statement, "using System.Reactive"

Update: The reason that this doesn't work is code that's not in the snippet. You declared TryAuthenticateCommand as IReactiveCommand which doesn't implement IObservable<T> (what would T be?).

In this case, since you're not providing an async method to go along with it, ReactiveCommand returns you the CommandParameter, which is an object. So declare it as ReactiveCommand<object> and everything works

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top