subscribe to an event with a generic argument

Topics: Prism v4 - WPF 4
Jan 20, 2013 at 6:51 PM


I have an event that uses an eventarg class that has a generic parameter. I want to publish this event and have the subscriber act on the generic parameter that was passed.

on the Publish side I have this:

PublishPrismEvent.Publish(new PrismPublishEventArgs<TPayload>(this.MethodName, this.TargetName, argument));

"argument" is defined as a generic parameter in the PrismPublishEventArgs class. On the subscribe side, I wish to subscribe to this event and then analyze that generic parameter using reflection, for example, in the event handler. I have:            

PrismPublishEvent PrismInternalPublishEvent = EventAggregator.GetEvent<PrismPublishEvent>(); PrismInternalPublishEvent.Subscribe(PrismInternalPublishEventHandler, ThreadOption.UIThread, false);

but it is throwing an error saying "Incorrect number of type parameters in reference to class PrismPublishEvent<T>"This should be doable... any help would be greatly appreciated. 



Jan 21, 2013 at 2:29 PM

Never mind on this.. found a much simpler solution...




Jan 21, 2013 at 2:51 PM
Edited Jan 21, 2013 at 2:52 PM

Hi Harold,

I'm glad you found a solution for this. So far the only approach I have seen to achieve this kind of scenarios is the one mentioned by Glenn Block in this blog post:

On the other hand, if you have found a different approach to achieve this functionality, perhaps you could share it with the rest of the community, as it might be useful for other users pursuing similar scenarios.

Best Regards,

Agustin Adami

Jan 21, 2013 at 9:56 PM

hi Agustin,


Yes, that was the blog post I had read too.. but all i needed for my circumstance was using an object type parameter instead of a generic... worked the way I needed it to... thanks very much for your reply!