Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Crash in Shell.cs: System.NullReferenceException

$
0
0

Hello,

Using XF v4.6.0.800

I can reproduce a crash in Shell.cs on this line:

public static bool GetNavBarIsVisible(BindableObject obj) => (bool)obj.GetValue(NavBarIsVisibleProperty);

Exception is: System.NullReferenceException

I analysed under which circumstance this is happening. Basically I have a form which shows answers to some questions. In that example this is a numeric field. When I tap the field, I show an edit form (modally) with a control to increment or decrement that value, and have a "Cancel" and a "Confirm" link to possibly save the change and in all cases pop the modal form off the stack and go back to the summary of answers.

Method to do show the modal:

var propertyViewModel = new PropertyViewModel(App.Service, viewModel.CalendarEvent, viewModel.Person)
{
    QuestionAnswer = questionAnswer,
    Type = propertyType,
    Title = questionAnswer.Text,
    Value = answer
};
var propertyPage = new EditPropertyPage
{
    BindingContext = propertyViewModel
};
propertyPage.Disappearing += (sender, e) =>
{
    if (propertyViewModel.Value != answer)
    {
        HasChanged = true;
    }
    questionAnswer.Answer = propertyViewModel.Value;
};

Navigation.PushModalAsync(propertyPage);

Here is my full step-by-step procedure to reproduce in my app:

How-to reproduce:

  1. Go to the list of participants
  2. Show answers from a member
  3. Switch to edit mode
  4. Edit a numeric question, change value, tap "Confirm" to save
  5. Edit again, next time you press "Confirm" the app will crash

By step-debugging I see something odd happening! The second time I invoke Navigation.PushModalAsync (step 5), the Disappearing event is firing right after pushing the modal async. The upon confirming or cancelling, the Disappearing event is fired as well, but this time it makes sense. I just don't get why this Disappearing event is fired at this point of time and I suspect this is somehow the source of the problem.

The difference between clicking Cancel and Confirm is this in my EditPropertyPage: Confirm starts the persisting event on the VM:

viewModel.Persist();
Navigation.PopModalAsync();

The operation will complete after the PopModalAsync(), asynchronously.

Any idea where to look for? Is it a bug in XF? I'm pretty sure it used to work a few versions back.


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>