0
votes

I'm trying to make an app in xamarin forms with EventAggregator and Prism. Till now I have made 3 Event, 2 of them work without problem, the last crash the app bun I don't understand why.

The event is this:

    public class AggiuntaRigaOrdineEvent : PubSubEvent<RigaOrdine>
{
}

RigaOrdine is the model Class. To publish the event I use:

_ea.GetEvent<AggiuntaRigaOrdineEvent>().Publish(Riga);

where

RigaOrdine Riga = new RigaOrdine();

As you can se in the picture taked just before the crash the Riga variabile is full:

enter image description here

So why it give me error:

System.NullReferenceException: 'Object reference not set to an instance of an object.'

EDIT: @Haukinger

The Excepion is thrown on the publish line, The stack call show:

0xAA in MokaDroid.ViewModels.NuovoArticoloOrdineClienteViewModel.<get_AggiungiRigaOrdine<get_AggiungiRigaOrdine>b__50_0>d at C:\Users\canap\source\repos\MokaDroid\MokaDroid\MokaDroid\ViewModels\NuovoArticoloOrdineClienteViewModel.cs:193,25 C#

The Subscriber is:

ea.GetEvent<AggiuntaRigaOrdineEvent>().Subscribe(RigaRicevuta);

Also if the app never arrive there. And the _ea is initialize in the constructor:

        public NuovoArticoloOrdineClienteViewModel(IPageDialogService DialogSerices, INavigationService navigationService, IEventAggregator ea)
    {
        _DialogSerices = DialogSerices;
        _navigationService = navigationService;
        _ea = ea;
    }

with IEventAggregator _ea; on the variable initialization on the begin of the viewmodel class.

What I don't understand, is that I have used the same way oter 2 times and it have work like a charm, here not.... and the 'Riga' variable is not NULL as you can see from the picture.

Here you have a list of all the variable and none are null... enter image description here

1
What exactly throws the exception? What does the stacktrace look like? What do the subscribers look like? Is _ea actually set to something that's not null?Haukinger
I have no idea what's in NuovoArticoloOrdineClienteViewModel.cs at line 193, I guess you'll have to do the debugging yourself.Haukinger
At that line is the publish lineStefano Santin
And what is null and why?Haukinger

1 Answers

0
votes

I have thought that the subscription of the event "read" the event when the page where is in is load. Now I have understand that The subscriber of the event read it at the same time. It have give me the error couse the variable of the subscriber was not initialized.