Bug 40502 - CarouselView NRE on MainPage change WinRT
Summary: CarouselView NRE on MainPage change WinRT
Alias: None
Product: Forms
Classification: Xamarin
Component: Windows ()
Version: 2.2.0
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Chris King
Depends on:
Reported: 2016-04-19 03:32 UTC by Adam
Modified: 2017-05-05 17:37 UTC (History)
5 users (show)

Tags: ac
Is this bug a regression?: ---
Last known good build:

Sample Repro (467.68 KB, application/x-zip-compressed)
2016-04-19 03:32 UTC, Adam

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Adam 2016-04-19 03:32:46 UTC
Created attachment 15760 [details]
Sample Repro


If I have a CarouselView on a Page, then I set the MainPage of the app to something different, I will get the below error on WinRT.

   at Xamarin.Forms.Platform.WinRT.CarouselViewRenderer.OnElementChanged(ElementChangedEventArgs`1 e)
   at Xamarin.Forms.Platform.WinRT.VisualElementRenderer`2.SetElement(VisualElement element)
   at Xamarin.Forms.Platform.WinRT.VisualElementRenderer`2.Dispose(Boolean disposing)
   at Xamarin.Forms.Platform.WinRT.VisualElementRenderer`2.Dispose()
   at Xamarin.Forms.Platform.WinRT.VisualElementExtensions.Cleanup(VisualElement self)
   at Xamarin.Forms.Platform.WinRT.PageRenderer.Dispose(Boolean disposing)
   at Xamarin.Forms.Platform.WinRT.VisualElementRenderer`2.Dispose()
   at Xamarin.Forms.Platform.WinRT.VisualElementExtensions.Cleanup(VisualElement self)
   at Xamarin.Forms.Platform.WinRT.Platform.<SetCurrent>d__44.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>b__3(Object state)
   at System.Threading.WinRTSynchronizationContext.Invoker.InvokeCore()

Attached sample project. Load it up and press the Test button.
Comment 1 Adam 2016-04-20 06:36:51 UTC
Still occurs in -pre3

Just noting that it all works ok in iOS.
Comment 2 Adam 2016-04-21 00:56:49 UTC
And just from more testing in trying to work around it, even if you go back or forward in a navigation page, it also throws the same error. You can't move away from a page with a CarouselView on it without the crash.
Comment 3 Ernest Williams 2016-04-26 17:02:41 UTC
I have the same issue on UWP in a MasterDetailPage.  The call stack starts out identically.

Object reference not set to an instance of an object.

   at Xamarin.Forms.Platform.UWP.CarouselViewRenderer.OnElementChanged(ElementChangedEventArgs`1 e)
   at Xamarin.Forms.Platform.UWP.VisualElementRenderer`2.SetElement(VisualElement element)
   at Xamarin.Forms.Platform.UWP.VisualElementRenderer`2.Dispose(Boolean disposing)
   at Xamarin.Forms.Platform.UWP.VisualElementRenderer`2.Dispose()
   at Xamarin.Forms.Platform.UWP.VisualElementExtensions.Cleanup(VisualElement self)
   at Xamarin.Forms.Platform.UWP.PageRenderer.Dispose(Boolean disposing)
   at Xamarin.Forms.Platform.UWP.VisualElementRenderer`2.Dispose()
   at Xamarin.Forms.Platform.UWP.MasterDetailPageRenderer.ClearDetail()
   at Xamarin.Forms.Platform.UWP.MasterDetailPageRenderer.UpdateDetail()
   at Xamarin.Forms.Platform.UWP.MasterDetailPageRenderer.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.MasterDetailPage.set_Detail(Page value)
   at Emerson.Pages.DashboardMasterDetailPage.NavigateBack(FormBuilder pageHeaderCell)
   at Xamarin.Forms.MessagingCenter.<>c__DisplayClass4_0`1.<Subscribe>b__0(Object sender, Object args)
   at Xamarin.Forms.MessagingCenter.InnerSend(String message, Type senderType, Type argType, Object sender, Object args)
   at Xamarin.Forms.MessagingCenter.Send[TSender](TSender sender, String message)
   at Emerson.Helpers.FormBuilder.<CreateSections>b__4_5()
   at Xamarin.Forms.Command.<>c__DisplayClass3_0.<.ctor>b__0(Object o)
   at Xamarin.Forms.Command.Execute(Object parameter)
   at Xamarin.Forms.TapGestureRecognizer.SendTapped(View sender)
   at Xamarin.Forms.Platform.UWP.VisualElementTracker`2.OnTap(Object sender, TappedRoutedEventArgs e)
Comment 4 Chris King 2017-05-05 17:37:55 UTC
CarouselView to be deprecated and replaced with https://github.com/xamarin/Xamarin.Forms/pull/853