Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IObservable<> missing .Subscribe extension methods

I'm using RX extensions and WF4 to create a workflow which reacts to observable messages to progress the workflow. To do this, I bring in an object containing an IObservable (ModuleMessage being my abstract class.) The problem I'm having is that .Subscribe fails to recognize any of its extension methods, namely the one for lambda extpressions/method groups. In the following code, I have references:

using System.Activities;
using System.Activities.Hosting;
using System.Collections.Generic;
using System.Reactive.Linq;

And also the following line of code:

    internal void AddModuleCallback(IModule module)
    {
        if (!addedCallback)
        {
            addedCallback = true;
            module.Messages.Where(m => m is MemberLeftModuleMessage || m is MemberRemovedModuleMessage).Subscribe(m => this.OnMemberExit(m)); // This line errors
        }
    }

    internal void OnMemberExit(ModuleMessage message)
    {
        // Gizmo was fired, resume the bookmark
        this.instance.BeginResumeBookmark(
            new Bookmark(ModuleVisit.BookmarkName),
            message is MemberLeftModuleMessage,
            r => this.instance.EndResumeBookmark(r),
            null);
    }

With the compile-time error of:

Error   1   Cannot convert lambda expression to type 'System.IObserver<Components.Messages.ModuleMessage>' because it is not a delegate type    <Removed>\WaitForModuleVisitExtension.cs    34  119 Components

Please note, this code is adapted from a sample and has not been factored out to my liking, I'm purely concerned in the problem at hand. I'm no pro with RX or WF4, but have used subscribe in this way elsewhere in the very same solution. I've added RX to this project via NuGet.

Edit: the following error if I use as a method group (instead of lambda):

Error   2   Argument 1: cannot convert from 'method group' to 'System.IObserver<Components.Messages.ModuleMessage>' <removed>\WaitForModuleVisitExtension.cs    34  119 Components
like image 240
Sprague Avatar asked May 09 '12 17:05

Sprague


1 Answers

You're missing this:

using System;

That's the namespace containing the ObservableExtensions static class with all the Subscribe extension methods.

Extension methods are "discovered" via using directives (as well as the namespace hierarchy of the code trying to use them).

like image 132
Jon Skeet Avatar answered Sep 28 '22 03:09

Jon Skeet