문제

I am loading the dll's using reflection and I then try to execute a method in that dll. That method has this line that subscribes to an event. I get an exception at this line

This line is in a dll that I am invoking dynamically using reflection

evntAgg.GetEvent<ExceptionEvent>().Subscribe(Message);

and the exception is something like this:

The Target of the IDelegateReference should be of type System.Action`1[[CustomType, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]. Parameter name: actionReference

this is the event handling method and is in the same dll that I am invoking dynamically

public void Message(ExceptionEvent exception)
{
//Do something
}

Any help would be appreciated?

도움이 되었습니까?

해결책

When using Prism's EventAggregator-class you will need to fulfill vertain requirements:

  1. Define an event that derives from CompositePresentationEvent<TEventArgs>, where TEventArgs derives from System.EventArgs

  2. Define a public method that handles your event, taking an instance of TEventArgs as parameter; for example:

    public void HandleExceptionEvent(ExceptionEventArgs eventArgs)
    {
    }
    

    The method needs to be public because otherwise the EventAggregator won't be able to invoke that method.

  3. Subscribe to your event:

    evntAgg.GetEvent<ExceptionEvent>.Subscribe(HandleExceptionEvent);
    

    Given that you have implemented step 2 as described that should work without a problem.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top