Silverlight 3 - Subscribe to method

Topics: Prism v2 - Silverlight 3
Feb 5, 2010 at 11:01 PM

Is there any way to subscribe to private/protected/internal method in EventAggregator?

Seems a bit dummy making all event-handling methods public.

Thank you.


Feb 11, 2010 at 8:07 PM


Prism’s EventAggregator uses this method to create a delegate (which is called when the event is published) if you are subscribing to the event using a weak reference. As the aforementioned document from MSDN explains, a MethodAccessException will be thrown if the caller does not have access to the method. As this is done in a class (and assembly) that is not the one where the method is declared, the method must be public to get this working correctly.

If you use a strong reference you can use subscribe with private methods. You can find information about how to subscribe to the event with weak/strong references here.

Please let me know if this helps.

Damian Schenkelman