Why is an ArgumentNullException exception thrown?

Aug 27, 2014 at 2:41 PM
Edited Aug 27, 2014 at 2:42 PM
HI all,

In the project I refer to, I use Prism MVVM, Unity and it is a Windows StoreApp for Win8.1
In my struggle though Prism I encounter a strange error - at least strange in my opinion.

In order to handle the event of a user selecting an Item from a ListView I have a Publisher of the event and I try in a ViewModel to Subscribe to that Event using the following statement (VB syntax) in the ViewModel:
        Sub New(InjectedEventAggregator As IEventAggregator)

            LocalEventAggregator = InjectedEventAggregator
            LocalEventAggregator.GetEvent(Of PersonIsSelectedEvent).Subscribe(ReactToPersonIsSelected(SelectedPerson))

        End Sub
And this is the intended handler of the event:
        Private Function ReactToPersonIsSelected(ReceivedPerson As Person) As Action(Of Person)
            If Not ReceivedPerson Is Nothing Then
                ActualPerson = ReceivedPerson 
            End If
            Return Nothing
        End Function
When I run this part of the application I get an error message: "Value cannot be null.
Parameter name: delegate". This refers to / comes from the DelegateReference class of the Prism library "PubSubEvents".

Appearently there is a parameter lacking, but which one? I have tried to mimic the ReferenceSolution of the Quickstart and don't see what I'm missing here. Probably something trivial.... I'm only just struggeling my way through Prism for three weeks now and the learning curve appears to be steep..

Anyone with a good suggestion?

Regards!
Aug 27, 2014 at 4:07 PM
Foud it!
The problem with translating from C# is that the call to Subscribe has to contain "AddressOf"

So the correct syntax for the statement is:
LocalEventAggregator.GetEvent(Of PersonIsSelectedEvent)().Subscribe(AddressOf ReactToPersonIsSelected)
Glad I sorted this one out!
Marked as answer by PeterKlein on 8/27/2014 at 9:07 AM