MethodInfo.Invoke 仅在 Prism EventAggregator 的调试模式下工作
我有一个 Prism 的 EventAgregator 的扩展方法,可以使用反射来发布事件。实现如下:
MethodInfo raiseMethod = typeof(Extensions).GetMethod("Raise", BindingFlags.Public | BindingFlags.Static).MakeGenericMethod(obj.GetType());
raiseMethod.Invoke(null, new object[] {eventAggregator, obj, eventType});
该方法调用需要类型化参数的扩展方法。此代码和事件工作正常,但仅限于调试模式。当切换到发布版本时,事件永远不会到达订阅者。
我尝试在订阅期间使用可选参数 keepSubscriberReferenceAlive
但这并不能解决问题。
关于如何解决这个问题有什么想法吗?
更新 我发现这个问题和上面的没有关系。似乎有一个过滤器只允许来自同一程序集中的事件。但这确实不能解释为什么代码在调试模式下可以工作。
I have a extension method for Prism's EventAgregator to publish an event using reflection. The implementation is as follows:
MethodInfo raiseMethod = typeof(Extensions).GetMethod("Raise", BindingFlags.Public | BindingFlags.Static).MakeGenericMethod(obj.GetType());
raiseMethod.Invoke(null, new object[] {eventAggregator, obj, eventType});
This method calls an extension method which requires a typed parameter. This code, and the eventing work fine, but only in Debug mode. When switching to a Release build the event never arrives at the subscriber.
I have tried using the optional parameter during subscription keepSubscriberReferenceAlive
but that does not fix the problem.
Any idea on how to fix this issue?
Update
I found that the issue is not releated to the above. It seems there is a filter in place which only allowed event from within the same assembly. But this really doesn't explain why the code worked while in debug mode.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论