Hit by CS1911 when trying to use non-generic overload of Observable.FromEvent
-
Wednesday, November 18, 2009 11:12 AM
Example code:
public static IObservable<IEvent<MouseEventArgs>> GetMouseDown(this Control control) { return Observable.FromEvent<MouseEventHandler, MouseEventArgs>( h => new MouseEventHandler(h), h => control.MouseDown += h, h => control.MouseDown -= h ); }CS1911: "Access to member 'System.EventHandler<TEventArgs>.Invoke(object, TEventArgs)' through a 'base' keyword from an anonymous method or iterator results in unverifiable code. Consider moving the access into a helper method on the containing type."
I know this is fixed in the C#4.0 compiler, but I'm playing in 3.5 and VS2008.
Anyone know if this slipped through the net? Or if I'm doing something wrong? Or if there is a workaround?
All Replies
-
Wednesday, November 18, 2009 3:58 PM
Hi Benjol,
this will get rid of the warning:
return Observable.FromEvent<MouseEventHandler, MouseEventArgs>(
h => (o,e)=>h(o,e),
h => control.MouseDown += h,
h => control.MouseDown -= h
);
Regards,
Jeffrey- Marked As Answer by Benjol Thursday, November 19, 2009 6:36 AM
-
Thursday, November 19, 2009 6:04 AMThanks,
and
ouch! my brain.

