Forum Xamarin.Forms

System.ArgumentException: 'jobject' must not be IntPtr.Zero

shamnadmhshamnadmh INMember
edited October 2015 in Xamarin.Forms

My app is crashing with the error message System.ArgumentException: 'jobject' must not be IntPtr.Zero . i checked the log files
in the attachment .This is happening while i remove an item from my observable collection i.e, removing one item from my cat page


  • TheRealJasonSmithTheRealJasonSmith USXamarin Team Xamurai

    What version of Forms are you on?

  • shamnadmhshamnadmh INMember

    @TheRealJasonSmith my xamarin forms version 2.0.5679.29810

  • GuiWaltrickeGuiWaltricke BRMember ✭✭

    @shamnadmh did you see this post?

    i have the same problem and the user @TorbenKruse send me a fix:

    Try Task.Yield();

    before pushing or removing item.

  • shamnadmhshamnadmh INMember

    update to my comment my xamarin forms version previous comment was not correct sorry for that

  • TheRealJasonSmithTheRealJasonSmith USXamarin Team Xamurai

    @shamnadmh I will need a reproduction case to try to figure out how you are getting interaction with a disposed element :/

  • Alex.LiuAlex.Liu USUniversity ✭✭

    I have the same error report from Insight I don't know how it happened and what caused that.

  • TheRealJasonSmithTheRealJasonSmith USXamarin Team Xamurai

    Unfortunately the IntPtr.Zero error is a very generic error that basically means "this android object was used after being disposed". Why they dont use that as the error in Xamarin.Android I dont know.

    It's not super likely that the way you are getting the error is the same way OP is.

  • AnthonyRamirezAnthonyRamirez USUniversity ✭✭✭

    @TheRealJasonSmith gotcha...hate those types of generic errors.

    Thanks for the info.

  • shamnadmhshamnadmh INMember
    edited October 2015

    @TheRealJasonSmith @AnthonyRamirez this is my code for delete an item from cart
    deleteAction. Clicked +=async ( sender, e) =>{ await Task.Yield(); try{ cm_items d; var mi = ((MenuItem)sender); d = (cm_items)mi.CommandParameter; d.IsAddedToCart = false; App.Instance.ViewModel.TempList.Remove(d); } catch (Exception ex){ System.Diagnostics.Debug.WriteLine(ex.ToString()); throw; } };

    iam adding a video to understanding what is happening there plz watch that

  • TheRealJasonSmithTheRealJasonSmith USXamarin Team Xamurai

    Okay I watched. Its uh difficult to tell exactly what might be causing it. Are you retaining instances of the pages when you navigate to them or are you creating them new each time? Does the new ListViewCachingStrategy help?

  • rzee7rzee7 INUniversity ✭✭✭✭✭

    Hi @shamnadmh

    can you please send your exception stack trace that are visible in video?


  • shamnadmhshamnadmh INMember

    thanks @rzee7 here is the log ,This log shows when the value remove from the cart
    @TheRealJasonSmith i'm not recreating the view each time just navigate , not using any code for that

  • rzee7rzee7 INUniversity ✭✭✭✭✭
    edited October 2015

    Hi @shamnadmh

    I got a chance to see this and found few things that may occurring an issue.
    I'm sure you are using App.Instance.ViewModel.TempList at many places that may be UI binding related. It seems like when you remove few items and again refill it and further you try to remove from this list somehow, an item conflicting may be not removing or a property you are using has some init issue.


       //Comment this line
        //TempList = TempList ?? new ObservableCollection<cm_items>();  
     //Also change the following:
     private readonly static ObservableCollection<cm_items> _tempList =new ObservableCollection<cm_items>();
        public ObservableCollection<cm_items> TempList
            get { return _tempList; }
           // set { _tempList = value; OnPropertyChanged("TempList"); }

    Now try, it should work!! looking forward to here you back. I tried to reproduce this issue after making these changes, Its not there, while before It was there. :)


  • shamnadmhshamnadmh INMember

    @rzee7 yes i have still the error after changing this but the log file is now different

  • shamnadmhshamnadmh INMember

    @rzee7 thanks for your reply . Still i'm getting error but there is no error while i delete item from cart with out any navigation . But if i navigate to the main page and again try to delete items from cart it will throw the same error ?

  • JacobPoulsen_JacobPoulsen_ DKMember ✭✭✭

    Im getting a somewhat same exception as @shamnadmh after updating to AppCompat v7, before that it worked fine. I have a page with a listview containing items. If i submit the items (using a web service) and call Navigation.PopModalAsync() it throws a System.ArgumentException: 'jobject' must not be IntPtr.Zero BUT only if I've been doing it once before. So the first time submitting, it goes just fine, second time (submitting the same thing) it breaks. Im creating new pages when i push the modal page, is that wrong?. If i just comment out the Navigation.PopModalAsync() it submits successfully and does not crash.

  • shamnadmhshamnadmh INMember

    @Jacob_b i'm still having this problem but i can suggest you some ways firstly ensure that no other values passing null . null value can cause this error , other one is just update your xamarin.forms .

Sign In or Register to comment.