Bug 34517 - Using navigation in context actions throws the exception
Summary: Using navigation in context actions throws the exception
Status: RESOLVED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Android ()
Version: 1.5.0
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Samantha Houts [MSFT]
URL:
Depends on:
Blocks:
 
Reported: 2015-10-02 07:23 UTC by bonobono
Modified: 2015-11-02 15:28 UTC (History)
5 users (show)

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


Attachments
Project with bug (365.15 KB, application/x-zip-compressed)
2015-10-02 07:23 UTC, bonobono
Details


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 FIXED

Description bonobono 2015-10-02 07:23:44 UTC
Created attachment 13172 [details]
Project with bug

It only happens on Android, iOS and WP works fine. It also works fine when I tap on 'ActionToolbar'. I'm using Xamarin.Forms 1.5.0.6447. I attached sample project.

Steps to reproduce:

1. Create Page and add ListView with context actions item

  <ContentPage.ToolbarItems>
    <ToolbarItem Text="ActionToolbar" Clicked="MenuItem_OnClicked" ></ToolbarItem>
  </ContentPage.ToolbarItems>

  <ListView x:Name="listView">
    <ListView.ItemTemplate>
      <DataTemplate>
        <ViewCell>
          <ViewCell.ContextActions>
            <MenuItem Text="ActionContext" Clicked="MenuItem_OnClicked"></MenuItem>
          </ViewCell.ContextActions>
          <StackLayout Orientation="Horizontal">
            <Label Text="{Binding .}"></Label>
          </StackLayout>
        </ViewCell>
      </DataTemplate>
    </ListView.ItemTemplate>
  </ListView>

2. Add event handler or command and use Navigation.PushAsync there

    public Page1()
    {
        InitializeComponent();
        listView.ItemsSource = new List<string>() {"Item1", "Item2", "Item2"};
    }

    private void MenuItem_OnClicked(object sender, EventArgs e)
    {
        App.Current.MainPage.Navigation.PushAsync(new Page2());
    }

3. Run the app, tap and hold on listview item for the moment, click on 'ActionContext' button, get:

10-02 13:17:45.685 I/MonoDroid( 1747): UNHANDLED EXCEPTION:
10-02 13:17:45.690 I/MonoDroid( 1747): System.ArgumentException: 'jobject' must not be IntPtr.Zero.
10-02 13:17:45.690 I/MonoDroid( 1747): Parameter name: jobject
10-02 13:17:45.690 I/MonoDroid( 1747): at Android.Runtime.JNIEnv.CallVoidMethod (intptr,intptr) [0x00010] in /Users/builder/data/lanes/2058/58099c53/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:546
10-02 13:17:45.690 I/MonoDroid( 1747): at Android.Views.ActionModeInvoker.Finish () [0x0002d] in /Users/builder/data/lanes/2058/58099c53/source/monodroid/src/Mono.Android/platforms/android-21/src/generated/Android.Views.ActionMode.cs:804
10-02 13:17:45.690 I/MonoDroid( 1747): at Xamarin.Forms.Platform.Android.CellAdapter.OnActionItemClicked (Android.Views.ActionMode,Android.Views.IMenuItem) <IL 0x0001e, 0x00127>
10-02 13:17:45.690 I/MonoDroid( 1747): at Android.Views.ActionMode/ICallbackInvoker.n_OnActionItemClicked_Landroid_view_ActionMode_Landroid_view_MenuItem_ (intptr,intptr,intptr,intptr) [0x00019] in /Users/builder/data/lanes/2058/58099c53/source/monodroid/src/Mono.Android/platforms/android-21/src/generated/Android.Views.ActionMode.cs:89
10-02 13:17:45.690 I/MonoDroid( 1747): at (wrapper dynamic-method) object.b5438ee0-f1e8-4439-b435-c613867c4144 (intptr,intptr,intptr,intptr) <IL 0x0001d, 0x00053>
10-02 13:17:45.700 W/art     ( 1747): JNI RegisterNativeMethods: attempt to register 0 native methods for md52ce486a14f4bcd95899665e9d932190b.JavaProxyThrowable
10-02 13:17:45.700 D/AndroidRuntime( 1747): Shutting down VM
Comment 1 bonobono 2015-10-02 14:16:32 UTC
BTW is there any workaround to fix this?
Comment 2 Dani 2015-10-12 05:27:44 UTC
I encounter this Exception as well on a pretty much identical setup.
iOS works flawlessly, Android crashes.
Comment 3 David Catteuw 2015-10-16 07:46:42 UTC
Same problem here, XF 1.5.0
This breaks an important feature in my application!

Xamarin team, please look into this!
Comment 4 David Catteuw 2015-10-16 08:26:47 UTC
Workaround from StackOverflow:

Adding:

await Task.Yield();

before Navigation.PushAsync helped.


http://stackoverflow.com/questions/32901334/using-navigation-in-context-actions-throws-the-exception
Comment 5 Jason Smith [MSFT] 2015-11-02 15:28:56 UTC
Should be fixed in 1.5.2-pre2