I have a viewmodel where I’m trying to use WhenActivated to dispose:
this.WhenActivated(disposables =>
{
this.WhenAnyValue(x => x.Selected)
.WhereNotNull()
.ObserveOn(RxApp.MainThreadScheduler)
.Do(x => _logger.LogInformation($"selected {x?.Name}"))
.Subscribe(x => process(x))
.DisposeWith(disposables);
});
And I get the error:
MyViewModel.cs(59, 22): [CS0121] The call is ambiguous between the following methods or properties: ‘System.Reactive.Disposables.DisposableMixins.DisposeWith(T, System.Reactive.Disposables.CompositeDisposable)’ and ‘Avalonia.Controls.Mixins.DisposableMixin.DisposeWith(T, System.Reactive.Disposables.CompositeDisposable)’
>Solution :
The problem is with DisposeWith extension methods that the compiler can’t differentiate between. One is from the System.Reactive.Disposables.DisposableMixins class, and the other is from the Avalonia.Controls.Mixins.DisposableMixin class.
- Fully qualify the DisposeWith method with the namespace of the
System.Reactive.Disposablesclass
or
- Add a
usingdirective for theSystem.Reactive.Disposablesnamespace at the top of your file