2

I'm trying to wire up Umbraco events using Rx:

Observable.FromEvent<TypedEventHandler<IPublishingStrategy, PublishEventArgs<IContent>>, PublishEventArgs<IContent>>(
h => ContentService.Published += h, h => ContentService.Published -= h).Subscribe(Console.WriteLine);

But I get an exception from deep within Rx when subscribing:

Cannot bind to the target method because its signature or security transparency is not compatible with that of the delegate type.

I can get it to work with a not-so-clean workaround:

var subject = new Subject<PublishEventArgs<IContent>>();
ContentService.Published += (sender, args) => subject.OnNext(args);
subject.Subscribe(Console.WriteLine);

But, how can I wire it up using Observable.FromEvent<>?

mnwsmit
  • 1,198
  • 2
  • 15
  • 31
  • 1
    Try `FromEventPattern` rather than `FromEvent` - the latter is for non-standard events and the former for events of the "sender, eventargs" variety. – Enigmativity Mar 30 '15 at 13:24
  • For a full discussion of how `Observable.FromEvent` works see http://stackoverflow.com/questions/19895373/how-to-use-observable-fromevent-instead-of-fromeventpattern-and-avoid-string-lit – James World Mar 30 '15 at 13:35

1 Answers1

0

Per suggestion from Enigmativity, this is the solution that works:

Observable.FromEventPattern<TypedEventHandler<IPublishingStrategy, PublishEventArgs<IContent>>, PublishEventArgs<IContent>>
            (h => ContentService.Published += h, h => ContentService.Published -= h).Subscribe(Console.WriteLine);
mnwsmit
  • 1,198
  • 2
  • 15
  • 31