Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullReferenceException in Android TabbedPageManager #21393

Closed
Mysame opened this issue Mar 22, 2024 · 3 comments · Fixed by #21432
Closed

NullReferenceException in Android TabbedPageManager #21393

Mysame opened this issue Mar 22, 2024 · 3 comments · Fixed by #21432

Comments

@Mysame
Copy link

Mysame commented Mar 22, 2024

Description

[AppCenterXamarinCrashes] Unhandled Exception from source=AppDomain
[AppCenterXamarinCrashes] System.NullReferenceException: Object reference not set to an instance of an object.
[AppCenterXamarinCrashes]    at Microsoft.Maui.Controls.Handlers.TabbedPageManager.Listeners.OnPageSelected(Int32 position) in D:\a\_work\1\s\src\Controls\src\Core\Platform\Android\TabbedPageManager.cs:line 843
[AppCenterXamarinCrashes]    at AndroidX.ViewPager2.Widget.ViewPager2.OnPageChangeCallback.n_OnPageSelected_I(IntPtr jnienv, IntPtr native__this, Int32 position) in C:\a\_work\1\s\generated\androidx.viewpager2.viewpager2\obj\Release
et6.0-android\generated\src\AndroidX.ViewPager2.Widget.ViewPager2.cs:line 318
[AppCenterXamarinCrashes]    at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPI_V(_JniMarshal_PPI_V callback, IntPtr jnienv, IntPtr klazz, Int32 p0) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:line 59
[mono-rt] [ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object.
[mono-rt]    at Microsoft.Maui.Controls.Handlers.TabbedPageManager.Listeners.OnPageSelected(Int32 position) in D:\a\_work\1\s\src\Controls\src\Core\Platform\Android\TabbedPageManager.cs:line 843
[mono-rt]    at AndroidX.ViewPager2.Widget.ViewPager2.OnPageChangeCallback.n_OnPageSelected_I(IntPtr jnienv, IntPtr native__this, Int32 position) in C:\a\_work\1\s\generated\androidx.viewpager2.viewpager2\obj\Release
et6.0-android\generated\src\AndroidX.ViewPager2.Widget.ViewPager2.cs:line 318
[mono-rt]    at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPI_V(_JniMarshal_PPI_V callback, IntPtr jnienv, IntPtr klazz, Int32 p0) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:line 59

Randomly happens upon navigating BACK from a page, our app consist of a NavigationPage holding a page that extends Microsoft.Maui.Controls.TabbedPage .

I found #10282 which seems to be this exact issue. Again, it happens sporadically.

Steps to Reproduce

    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class AssignmentTabbedContainer : Microsoft.Maui.Controls.TabbedPage
    {
        public bool IsFirstLoad { get; set; }
        public bool isAttachmentPressed { get; set; }
        public AssignmentTabbedContainer()
        {
            InitializeComponent();
        }
    }
<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage x:Class="Signco.Mobile.MaaS.Maui.Pages.AssignmentTabbedContainer.AssignmentTabbedContainer"
            xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
            xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
            xmlns:shared="clr-namespace:Signco.Mobile.MaaS.Maui.Shared"
            xmlns:android="clr-namespace:Microsoft.Maui.Controls.PlatformConfiguration.AndroidSpecific;assembly=Microsoft.Maui.Controls"
            android:TabbedPage.ToolbarPlacement="Bottom"
            x:DataType="viewModels:TabbedPageViewModel"
            ItemsSource="{Binding Tabs}"
            SelectedItem="{Binding SelectedTab, Mode=TwoWay}">

    <NavigationPage.TitleView>
        <shared:TitleView Title="{Binding Title}" />
    </NavigationPage.TitleView>

    <TabbedPage.ItemTemplate>
        <DataTemplate x:DataType="viewModels:TabContentPageViewModel">
            <ContentPage Title="{Binding Title}"
                         Shell.NavBarIsVisible="false"
                         Content="{Binding Content.Content}"
                         IconImageSource="{Binding Icon}" />
        </DataTemplate>
    </TabbedPage.ItemTemplate>
</TabbedPage>

Navigating "back" can cause this error to happen.

Link to public reproduction project repository

No response

Version with bug

8.0.10 SR3

Is this a regression from previous behavior?

Yes, this used to work in Xamarin.Forms

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

No response

@Mysame Mysame added the t/bug Something isn't working label Mar 22, 2024
@PureWeen PureWeen added s/needs-repro Attach a solution or code which reproduces the issue area-controls-tabbedpage TabbedPage labels Mar 22, 2024
@Mysame
Copy link
Author

Mysame commented Mar 22, 2024

var Element = _tabbedPageManager.Element;

TabbedPageManager's Element gets checked for null seemingly everywhere, except for in Listener's OnPageSelected
if (_previousPage != Element.CurrentPage)
This being line 843 as referenced by the stacktrace, I can only assume Element is null here.

I'm sorry I can't quite give a repro as of right now, as it is an internal project for a client. However if need be I can deliver it to someone directly.

@dotnet-policy-service dotnet-policy-service bot added s/needs-attention Issue has more information and needs another look and removed s/needs-repro Attach a solution or code which reproduces the issue labels Mar 22, 2024
@rmarinho rmarinho added s/needs-repro Attach a solution or code which reproduces the issue and removed s/needs-attention Issue has more information and needs another look labels Mar 25, 2024
Copy link
Contributor

Hi @Mysame. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@Utkarsh-Gangwar
Copy link

Utkarsh-Gangwar commented Apr 8, 2024

we are getting same issue with tabbed page and crash is happening with .netMAUI Microsoft.MAUI.Controls 8.0.7 @rmarinho could you please let us know in which MAUI version this fix going to be released or else please let us know any workaround for this issue.
Thanks in advance

@github-actions github-actions bot locked and limited conversation to collaborators May 9, 2024
@samhouts samhouts added this to the .NET 8 SR4 milestone May 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants