Bug 52376 - NullReferenceException when change the MainPage if the old page contains a ListView
Summary: NullReferenceException when change the MainPage if the old page contains a Li...
Status: RESOLVED NORESPONSE
Alias: None
Product: Forms
Classification: Xamarin
Component: iOS ()
Version: 2.3.3
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Paul DiPietro [MSFT]
URL:
Depends on:
Blocks:
 
Reported: 2017-02-08 08:44 UTC by Suat Korkmaz
Modified: 2017-06-21 13:57 UTC (History)
5 users (show)

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

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:
Status:
RESOLVED NORESPONSE

Description Suat Korkmaz 2017-02-08 08:44:50 UTC
Description:
ContentPage is unable to dispose if a child is a ListView when unloading.

Overview:
You have a MasterDetailPage as MainPage. Load a ContentPage as Detail. The ContentPage contains a ListView. When you set another page as Detail the old page is unable to dispose the ListView.

Steps to Reproduce:
1- Create a Portable project.
2- Add a MasterDetailPage to the page you will load as Main page.
3- Create a ContentPage and put a ListView and a button in it.
4- Do not use any platform specific renderer on the ListView
5- Fill the ListView
6- In the clicked handler of the button set a new empty page to the app:
App.Current.MainPage = new ContentPage();

7- Set the ContentPage as Detail that you created in step #3
8- Run the app (ListView fills)
9- Click the button.


Actual Result: 
You should get a System.NullReferenceException

Expected Result:
You shouldn't get a System.NullReferenceException

Additional Information:
As a workaround I created a ListViewRenderer for iOS like:

public class CustomListViewRenderer : ListViewRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<ListView> e)
        {
            base.OnElementChanged(e);
        }
        protected override void Dispose(bool disposing)
        {
            //base.Dispose(disposing);
        }

When I comment out the //base.Dispose(disposing); line then the app works.

PS: I'm sorry that I am unable to create a sample app right now.
Comment 1 Paul DiPietro [MSFT] 2017-03-27 03:42:34 UTC
I am not able to reproduce this but would like to get more info. Can you please verify the Forms version, iOS version, and device or simulator, and possibly upload a reproduction? I've put the ContentPage as the Detail with the ListView and button, and clicking the button sets App.Current.MainPage to a new ContentPage. Clicking that does not appear to cause a crash on my simulator running 10.2.
Comment 2 Rui Marinho 2017-06-21 13:57:50 UTC
Because we have not received a reply to our request for more information we are closing this issue. If you are still encountering this issue, please reopen the ticket with the requested information. Thanks!