CarouselView icon indicating copy to clipboard operation
CarouselView copied to clipboard

[UWP] Crash when calling FreshMVVM RaisePageWasPopped

Open RuddyOne opened this issue 7 years ago • 10 comments
trafficstars

This is a bit random but I seem to be struggling with what this could be! I have a carousel view on pretty much all my applications pages (my app uses a navigation page) but when I call pageModel.RaisePageWasPopped(); in FreshMVVM I get the following crash.

-		$exception	{System.NullReferenceException: Object reference not set to an instance of an object.
   at CarouselView.FormsPlugin.Abstractions.IEnumerableExtensions.GetCount(IEnumerable e)
   at CarouselView.FormsPlugin.UWP.CarouselViewRenderer.SetArrowsVisibility()
   at CarouselView.FormsPlugin.UWP.CarouselViewRenderer.OnElementPropertyChanged(Object sender, PropertyChangedEventArgs e)
   at System.ComponentModel.PropertyChangedEventHandler.Invoke(Object sender, PropertyChangedEventArgs e)
   at Xamarin.Forms.BindableObject.OnPropertyChanged(String propertyName)
   at Xamarin.Forms.Element.OnPropertyChanged(String propertyName)
   at Xamarin.Forms.BindableObject.SetValueActual(BindableProperty property, BindablePropertyContext context, Object value, Boolean currentlyApplying, SetValueFlags attributes, Boolean silent)
   at Xamarin.Forms.BindableObject.SetValueCore(BindableProperty property, Object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes)
   at Xamarin.Forms.BindingExpression.ApplyCore(Object sourceObject, BindableObject target, BindableProperty property, Boolean fromTarget)
   at Xamarin.Forms.BindingExpression.Apply(Object sourceObject, BindableObject target, BindableProperty property)
   at Xamarin.Forms.Binding.Apply(Object context, BindableObject bindObj, BindableProperty targetProperty, Boolean fromBindingContextChanged)
   at Xamarin.Forms.BindableObject.ApplyBindings(Boolean skipBindingContext, Boolean fromBindingContextChanged)
   at Xamarin.Forms.BindableObject.SetInheritedBindingContext(BindableObject bindable, Object value)
   at Xamarin.Forms.Element.SetChildInheritedBindingContext(Element child, Object context)
   at Xamarin.Forms.Element.<OnBindingContextChanged>b__78_0(BindableObject child, Object bc)
   at Xamarin.Forms.BindableObjectExtensions.PropagateBindingContext[T](BindableObject self, IList`1 children, Action`2 setChildBindingContext)
   at Xamarin.Forms.Element.OnBindingContextChanged()
   at Xamarin.Forms.View.OnBindingContextChanged()
   at Xamarin.Forms.Grid.OnBindingContextChanged()
   at Xamarin.Forms.BindableObject.SetInheritedBindingContext(BindableObject bindable, Object value)
   at Xamarin.Forms.Element.SetChildInheritedBindingContext(Element child, Object context)
   at Xamarin.Forms.Element.<OnBindingContextChanged>b__78_0(BindableObject child, Object bc)
   at Xamarin.Forms.BindableObjectExtensions.PropagateBindingContext[T](BindableObject self, IList`1 children, Action`2 setChildBindingContext)
   at Xamarin.Forms.Element.OnBindingContextChanged()
   at Xamarin.Forms.View.OnBindingContextChanged()
   at Xamarin.Forms.BindableObject.SetInheritedBindingContext(BindableObject bindable, Object value)
   at Xamarin.Forms.TemplatedView.SetChildInheritedBindingContext(Element child, Object context)
   at Xamarin.Forms.Element.<OnBindingContextChanged>b__78_0(BindableObject child, Object bc)
   at Xamarin.Forms.BindableObjectExtensions.PropagateBindingContext[T](BindableObject self, IList`1 children, Action`2 setChildBindingContext)
   at Xamarin.Forms.Element.OnBindingContextChanged()
   at Xamarin.Forms.View.OnBindingContextChanged()
   at Xamarin.Forms.ContentView.OnBindingContextChanged()
   at Xamarin.Forms.BindableObject.SetInheritedBindingContext(BindableObject bindable, Object value)
   at Xamarin.Forms.TemplatedPage.SetChildInheritedBindingContext(Element child, Object context)
   at Xamarin.Forms.Element.<OnBindingContextChanged>b__78_0(BindableObject child, Object bc)
   at Xamarin.Forms.BindableObjectExtensions.PropagateBindingContext[T](BindableObject self, IList`1 children, Action`2 setChildBindingContext)
   at Xamarin.Forms.Element.OnBindingContextChanged()
   at Xamarin.Forms.Page.OnBindingContextChanged()
   at Xamarin.Forms.ContentPage.OnBindingContextChanged()
   at Xamarin.Forms.BindableObject.BindingContextPropertyChanged(BindableObject bindable, Object oldvalue, Object newvalue)
   at Xamarin.Forms.BindableObject.SetValueActual(BindableProperty property, BindablePropertyContext context, Object value, Boolean currentlyApplying, SetValueFlags attributes, Boolean silent)
   at Xamarin.Forms.BindableObject.SetValueCore(BindableProperty property, Object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes)
   at Xamarin.Forms.BindableObject.SetValue(BindableProperty property, Object value, Boolean fromStyle, Boolean checkAccess)
   at FreshMvvm.FreshBasePageModel.RaisePageWasPopped()
   at MyApp.Services.Navigation.FreshMvvmCustomNavigation.PopToPageIndex(Int32 pageIndex, Boolean animate)
   at FreshMvvm.PageModelCoreMethods.<PopToPageIndex>d__14.MoveNext()}	System.NullReferenceException

Note that there isn't any custom code for that method, I just call it when popping pages in the navigation stack. I'm hoping someone can help me out and point me in the right direction. This seems completely random to me.

I will also show the PopToPageIndex method to give this some context.

        public Task PopToPageIndex(int pageIndex, bool animate = true)
        {
            while ((Navigation.NavigationStack.Count - 2) > pageIndex)
            {
                var page = Navigation.NavigationStack[Navigation.NavigationStack.Count - 2];
                var pageModel = page.GetModel();

                if (Navigation.NavigationStack.First() != page)
                    pageModel.RaisePageWasPopped();

                Navigation.RemovePage(page);
            }

            return Navigation.PopAsync(animate);
        }

RuddyOne avatar Oct 30 '18 08:10 RuddyOne

I have 0 experience with FreshMVVM.

alexrainman avatar Nov 10 '18 23:11 alexrainman

Can you provide a demo?

alexrainman avatar Nov 10 '18 23:11 alexrainman

@alexrainman Will try to put one together soon and get back to you.

RuddyOne avatar Nov 13 '18 12:11 RuddyOne

@alexrainman I have created a small test app for this issue.

  1. Open the project and run the UWP app
  2. Click the "Click me" button once, this opens the same view but as a model
  3. Click the "Click me" button once, this will now close the model
  4. Check the output, you will see the error (Exception thrown: 'System.NullReferenceException' in CarouselView.FormsPlugin.Abstractions.dll) logged in there. You will also see the first page now having no content in the carousel view.

This project also contains a demo for the problem I am having that I think is related to #222. I wont go into detail here, let me know if you want me to open a new bug or put this project also in the #222 issue. TestApp.zip

RuddyOne avatar Nov 19 '18 12:11 RuddyOne

facing same problem when in master detail app, listview menu item selected navigationDrawer.ContentView = new Page1().Content; and you will see the error (Exception thrown: 'System.NullReferenceException

anson3923 avatar Nov 21 '18 05:11 anson3923

I can see the main page with no content but I can't see the crash.

alexrainman avatar Dec 27 '18 18:12 alexrainman

@alexrainman Make sure in your VS settings you have "Enable Just My Code" unchecked in debugging, I forgot I had it on just then and was unable to see the error. Now it is off I am seeing the error from the project I uploaded.

RuddyOne avatar Jan 14 '19 14:01 RuddyOne

I have hooked in your project so I can see a little bit of what is going on. From what I can see we fall over here (IEnumerableExtensions):

public static int GetCount(this IEnumerable e)
{
     var enumerator = e.GetEnumerator();
     int i = 0;
     while (enumerator.MoveNext())
     {
          i++;
     }
     return i;
}

e is null and it falls over on e.GetEnumerator();. Hope this gives you a little more to go on while I still look into this.


GetCount is being called from here and Element.ItemsSource is null.

void SetArrowsVisibility()
{
     if (prevBtn == null || nextBtn == null) return;
     prevBtn.Visibility = Element.Position == 0 || Element.ItemsSource.GetCount() == 0 ? Visibility.Collapsed : Visibility.Visible;
     nextBtn.Visibility = Element.Position == Element.ItemsSource.GetCount() - 1 || Element.ItemsSource.GetCount() == 0 ? Visibility.Collapsed : Visibility.Visible;
}

RuddyOne avatar Jan 14 '19 14:01 RuddyOne

This definitely helps.

alexrainman avatar Jan 14 '19 15:01 alexrainman

Manage to get anywhere with this? Still a huge issue for me.

RuddyOne avatar Mar 08 '19 12:03 RuddyOne