Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Ambiguous Invocation on WhenActivated

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)’

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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.Disposables class

or

  • Add a using directive for the System.Reactive.Disposables namespace at the top of your file
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading