Bug 39790 - "binding jobject must not be intptr.zero" when replacing ScollView's content with binding
Summary: "binding jobject must not be intptr.zero" when replacing ScollView's content ...
Status: CONFIRMED
Alias: None
Product: Forms
Classification: Xamarin
Component: Android ()
Version: 2.1.0
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-03-20 08:20 UTC by Falko Schindler
Modified: 2016-03-21 23:27 UTC (History)
3 users (show)

Tags: ac
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 for Bug 39790 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
CONFIRMED

Description Falko Schindler 2016-03-20 08:20:43 UTC
The following app shows a ScrollView container and two buttons:
1) "Reload" replaces the SwitchView's content with a Switch bound to some static bindable property.
2) "GC.Collect" triggers garbage collection.

    public class App : Application
    {
        public App()
        {
            var container = new ScrollView { Content = new Toggle() };

            MainPage = new ContentPage {
                Content = new StackLayout {
                    Children = {
                        new Button {
                            Text = "Reload",
                            Command = new Command(o => container.Content = new Toggle()),
                        },
                        new Button {
                            Text = "GC.Collect",
                            Command = new Command(o => GC.Collect()),
                        },
                        container,
                    },
                },
            };
        }
    }

    public class Toggle: Switch
    {
        public static Setting Setting = new Setting();

        public Toggle()
        {
            BindingContext = Setting;
            this.SetBinding(Switch.IsToggledProperty, Setting.OnProperty.PropertyName);
        }
    }

    public class Setting: BindableObject
    {
        public static readonly BindableProperty OnProperty = BindableProperty.Create("On", typeof(bool), typeof(Setting), false);

        public bool On {
            get { return (bool)GetValue(OnProperty); }
            set { SetValue(OnProperty, (bool)value); }
        }
    }

When reloading the content after garbage collection, the app crashes with "System.ArgumentException: 'jobject' must not be IntPtr.Zero" pointing to the setter of "Setting.On".

Some more observations:
* The crash doesn't happen with a ContentView container rather than ScrollView.
* Tested with Android 4.4.4 only.
* A workaround is to add (container.Content as Toggle).BindingContext = null; in the reload command before setting container.Content.