IObservable<> missing .Subscribe extension methods

浪尽此生 提交于 2019-12-21 07:31:22

问题


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

回答1:


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



来源:https://stackoverflow.com/questions/10521000/iobservable-missing-subscribe-extension-methods

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!