使用一个以.Net 4.5为目标的项目,我有一段代码可以做到这一点
public static IObservable<string> Receive(SubscriberSocket subp)
{
return Observable
.Create<string>(o =>
Observable.Using<string, SubscriberSocket>(() =>
{
subp.Connect("inproc://test");
subp.Subscribe("");
return subp;
}, sub =>
Observable.FromEventPattern<EventHandler<NetMQSocketEventArgs>, NetMQSocketEventArgs>(
h => sub.ReceiveReady += h,
h => sub.ReceiveReady -= h)
.Select(x => sub.ReceiveString()))
.Subscribe(o));
}
但是,它抱怨我需要System.Reactive.Interfaces, Version=3.0.0.0
即使该程序集已添加到项目中?
/home/idf/Documents/csharp/NetMQObs/TestNetMQ/TestNetMQ/Program.cs(25,25):错误 CS0012:类型“IQbservable<>”在未引用的程序集中定义。您必须添加对程序集“System.Reactive.Interfaces, Version=3.0.0.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263”的引用。(CS0012) (TestNetMQ)
按照下面的建议添加 2.2.5 版本后,现在我收到此错误。将调用更改为ReceiveFrameString
编译,但 YMMV。
/home/idf/Documents/csharp/NetMQObs/TestNetMQ/TestNetMQ/Program.cs(42,42): Error CS1061: 'SubscriberSocket' does not contain a definition for 'ReceiveString' and no extension method 'ReceiveString' accepting a first argument of type 'SubscriberSocket' could be found (are you missing a using directive or an assembly reference?) (CS1061) (TestNetMQ)