CallerMemberName Attribute not working with EventAggregator

650 views Asked by At

I am working in Prism where CallerMember attribute is not working well with my code. I have a Close method and want to know from where the Close method get calls. Normally the memberName parameter marked using CallerMember attribute should receive calling method name. But the Subscribing and unsubscribing code shows, this eventAggregator has some invalid arguments. Any help would greatly appreciated.

private void Close(bool isOKCommand,[CallerMemberName] string memberName = "")
{
        this.eventAggregator.GetEvent<ShowWarningMessageEvent>().Unsubscribe(this.Close);
        if (isOKCommand)
        {
            //Doing some operations;
        }
}
1

There are 1 answers

1
S2S2 On

There could be an issue in the way you have called and used Unsubscribe method of EventAggregator which is the reason you are getting Invalid Arguments exception.

Unsubscribing to a Prism Event requires either a subscription token returned by the Subscribe method or a callback delegate you passed to the Subscribe method. Please refer MSDN for more information

SubscriptionToken subscriptionToken = this.eventAggregator.GetEvent<ShowWarningMessageEvent>().Subscribe(<YourSubscribeMethod>);
this.eventAggregator.GetEvent<ShowWarningMessageEvent>().Unsubscribe(subscriptionToken);