You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] WeakEventManager throws InvalidHandleEventException for closed DynamicMethod handlers, like Expression.Compile() #347
WeakEventManager.RaiseEvent throws InvalidHandleEventException ("Parameter count mismatch", inner TargetParameterCountException) when the handler is a closedDynamicMethod delegate. For example:
EventManagerService.HandleEvent calls dynamicMethod.Invoke(instance, [sender, eventArgs]). A DynamicMethod is static, so Invoke ignores instance. The bound target has to be the first element of the argument array instead.
A fix needs a design decision. WeakEventManager holds the delegate's Target only weakly, and for Expression.Compile() that target is a compiler-generated Closure nothing else references, so the subscription can disappear at the next GC. Options:
Support these handlers: when instance isn't null and the DynamicMethod takes one more parameter than the arguments, pass instance as the first argument.
Or reject them in AddEventHandler with a clear exception.
Activity