I have a native COM library (which I can modify), and I have an F# application trying to consume an event with Rx, from an Interop library, referenced in the project.
let events = obj :?> _IInteropEvents_Event
let disposable =
Observable.take 1 events.ComEventArrived
|> Observable.subscribe (fun sender data -> ()) // sender : ISender, data : IData
The error message here, which I don't fully understand, is:
The event 'ComEventArrived' has a non-standard type. If this event is declared in another CLI language, you may need to access this event using the explicit add_ComEventArrived and remove_ComEventArrived methods for the event. If this event is declared in F#, make the type of the event an instantiation of either 'IDelegateEvent<>' or 'IEvent<,_>'.
I don't mind using add_ComEventArrived
but I can't figure out how to make this work with Observable
Curiously, ComEventArrived
has 2 arguments of internal interop types, if I try to subscribe to other events that simply marshal an IUnknown, it works and I get no "non-standard type" error:
let events = obj :?> _ISnapshotEvents_Event
let disposable =
Observable.take 1 events.SnapshotEventArrived
|> Observable.subscribe (fun sender -> ()) // sender : IUnknown (unit)
How can I do any of the following to solve the issue?
- Modify COM library to fix the non-standard event type error.
- Use explicit add_/remove_ functions with Observer.take/Observer.subscribe.
- Other ways of firing an event n times before unsubscribing, without using mutable/lock.
I have read so far: