Hi,
I'm getting null ref errors in TaskController.OnTaskComplete method because the "request" field is null. I dug deeper and while I don't have a solid understanding of why it's happening here is what is happening:
1. Page A does EventAggregator.RequestTask<PhotoChooserTask>()
2. The PhotoChooserTask completes, Page A's async void Handle(TaskCompleted<PhotoResult> completed) fires.
3. Page A navigates to Page B which does EventAggregator.RequestTask<ShareMediaTask>()
4. Pres Back button twice to get back to Page A.
5. Page A does EventAggregator.RequestTask<PhotoChooserTask>()
6. The PhotoChooserTask completes and the NullReferenceException crash happens in the TaskController.OnTaskComplete.
The culprit is this, on step 5 the TaskController handles the TaskExecutionRequested and executes this bit of code:
```
var @event = taskType.GetEvent("Completed");
if(@event != null) {
request = message;
@event.AddEventHandler(request.Task, CreateOnTaskCompletedDelegate(@event));
}
```
As soon as the event handler is attached the Chooser's event fires with TaskResult.Cancel result. TaskController.OnTaskComplete executes and clears out the __request__ field.
So when the Chooser is actually shown and completes and OnTaskComplete is fired again the __request__ field is null.
I'm getting null ref errors in TaskController.OnTaskComplete method because the "request" field is null. I dug deeper and while I don't have a solid understanding of why it's happening here is what is happening:
1. Page A does EventAggregator.RequestTask<PhotoChooserTask>()
2. The PhotoChooserTask completes, Page A's async void Handle(TaskCompleted<PhotoResult> completed) fires.
3. Page A navigates to Page B which does EventAggregator.RequestTask<ShareMediaTask>()
4. Pres Back button twice to get back to Page A.
5. Page A does EventAggregator.RequestTask<PhotoChooserTask>()
6. The PhotoChooserTask completes and the NullReferenceException crash happens in the TaskController.OnTaskComplete.
The culprit is this, on step 5 the TaskController handles the TaskExecutionRequested and executes this bit of code:
```
var @event = taskType.GetEvent("Completed");
if(@event != null) {
request = message;
@event.AddEventHandler(request.Task, CreateOnTaskCompletedDelegate(@event));
}
```
As soon as the event handler is attached the Chooser's event fires with TaskResult.Cancel result. TaskController.OnTaskComplete executes and clears out the __request__ field.
So when the Chooser is actually shown and completes and OnTaskComplete is fired again the __request__ field is null.