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 UpdateLeftBarButtonItem #14801

Open
dantovalphas opened this issue Apr 27, 2023 · 8 comments
Open

NullReferenceException in UpdateLeftBarButtonItem #14801

dantovalphas opened this issue Apr 27, 2023 · 8 comments
Labels
area-controls-toolbar ToolBar platform/android 🤖 s/triaged Issue has been reviewed t/bug Something isn't working
Milestone

Comments

@dantovalphas
Copy link

Description

Fatal Exception: android.runtime.JavaProxyThrowable: System.NullReferenceException: Object reference not set to an instance of an object
at Microsoft.Maui.Controls.Platform.Compatibility.ShellToolbarTracker.get_MauiContext()
at Microsoft.Maui.Controls.Platform.Compatibility.ShellToolbarTracker.UpdateLeftBarButtonItem(Context context, Toolbar toolbar, DrawerLayout drawerLayout, Page page)
at System.Threading.Tasks.Task.<>c.b__128_0(Object )
at Android.App.SyncContext.<>c__DisplayClass2_0.b__0()
at Java.Lang.Thread.RunnableImplementor.Run()
at Java.Lang.IRunnableInvoker.n_Run(IntPtr , IntPtr )
at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V(_JniMarshal_PP_V , IntPtr , IntPtr )
at mono.java.lang.RunnableImplementor.n_run(RunnableImplementor.java)
at mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:31)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:211)
at android.app.ActivityThread.main(ActivityThread.java:6769)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

Steps to Reproduce

Bug reported by Firebase Crashlytics in Android
image
com.alphas.growingfamily_issue_50301eaa3143b6359a31e950bc7a3b35_crash_session_6449CF32029A00014999FAE3E68583FE_DNE_0_v2_stacktrace.txt

Link to public reproduction project repository

none

Version with bug

7.0 (current)

Last version that worked well

7.0 (current)

Affected platforms

Android

Affected platform versions

Android 9

Did you find any workaround?

No response

Relevant log output

Fatal Exception: android.runtime.JavaProxyThrowable: System.NullReferenceException: Object reference not set to an instance of an object
   at Microsoft.Maui.Controls.Platform.Compatibility.ShellToolbarTracker.get_MauiContext()
   at Microsoft.Maui.Controls.Platform.Compatibility.ShellToolbarTracker.UpdateLeftBarButtonItem(Context context, Toolbar toolbar, DrawerLayout drawerLayout, Page page)
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_0(Object )
   at Android.App.SyncContext.<>c__DisplayClass2_0.<Post>b__0()
   at Java.Lang.Thread.RunnableImplementor.Run()
   at Java.Lang.IRunnableInvoker.n_Run(IntPtr , IntPtr )
   at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V(_JniMarshal_PP_V , IntPtr , IntPtr )
       at mono.java.lang.RunnableImplementor.n_run(RunnableImplementor.java)
       at mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:31)
       at android.os.Handler.handleCallback(Handler.java:873)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:211)
       at android.app.ActivityThread.main(ActivityThread.java:6769)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
@dantovalphas dantovalphas added the t/bug Something isn't working label Apr 27, 2023
@jsuarezruiz jsuarezruiz added this to the Backlog milestone Apr 27, 2023
@jsuarezruiz jsuarezruiz self-assigned this Apr 27, 2023
@ghost
Copy link

ghost commented Apr 27, 2023

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.

@jsuarezruiz jsuarezruiz removed their assignment Apr 28, 2023
@michele-guion
Copy link

Hello,
we have the same issue in our Shell app, on different devices and different Android versions (no recognizable patterns).
We are not able to reproduce the issue but we find it often in our logs on Google Play Console.
Please, take a look at this, it's causing lots of crashes.

@Stefan171086
Copy link

Stefan171086 commented Nov 9, 2023

Can confirm this issue in our Shell app. Also found it via Crashlytics report. Similar stacktrace.

Microsoft.Maui.Controls.Platform.Compatibility.ShellToolbarTracker.get_MauiContext Microsoft.Maui.Controls.Platform.Compatibility.ShellToolbarTracker+<UpdateLeftBarButtonItem>d__51.MoveNext System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw System.Threading.Tasks.Task+<>c.<ThrowAsync>b__128_0 Android.App.SyncContext+<>c__DisplayClass2_0.<Post>b__0 Java.Lang.Thread+RunnableImplementor.Run Java.Lang.IRunnableInvoker.n_Run Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V mono.java.lang.RunnableImplementor.n_run (RunnableImplementor.java) mono.java.lang.RunnableImplementor.run (RunnableImplementor.java:31) android.os.Handler.handleCallback (Handler.java:938) android.os.Handler.dispatchMessage (Handler.java:99) android.os.Looper.loopOnce (Looper.java:226) android.os.Looper.loop (Looper.java:313) android.app.ActivityThread.main (ActivityThread.java:8663) java.lang.reflect.Method.invoke (Method.java) com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:567) com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1135)

@jsuarezruiz : Are there any efforts to solve this problem in the near future?
@michele-guion : Did you find a workaround or a solution to get around this problem?

Thx Stefan

@DimaKB
Copy link

DimaKB commented Nov 29, 2023

@PureWeen Any solution for this?
Still not works on version 8.
I have the same issue when open application through deep link.

@michele-guion
Copy link

Can confirm this issue in our Shell app. Also found it via Crashlytics report. Similar stacktrace.

Microsoft.Maui.Controls.Platform.Compatibility.ShellToolbarTracker.get_MauiContext Microsoft.Maui.Controls.Platform.Compatibility.ShellToolbarTracker+<UpdateLeftBarButtonItem>d__51.MoveNext System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw System.Threading.Tasks.Task+<>c.<ThrowAsync>b__128_0 Android.App.SyncContext+<>c__DisplayClass2_0.<Post>b__0 Java.Lang.Thread+RunnableImplementor.Run Java.Lang.IRunnableInvoker.n_Run Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V mono.java.lang.RunnableImplementor.n_run (RunnableImplementor.java) mono.java.lang.RunnableImplementor.run (RunnableImplementor.java:31) android.os.Handler.handleCallback (Handler.java:938) android.os.Handler.dispatchMessage (Handler.java:99) android.os.Looper.loopOnce (Looper.java:226) android.os.Looper.loop (Looper.java:313) android.app.ActivityThread.main (ActivityThread.java:8663) java.lang.reflect.Method.invoke (Method.java) com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:567) com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1135)

@jsuarezruiz : Are there any efforts to solve this problem in the near future? @michele-guion : Did you find a workaround or a solution to get around this problem?

Thx Stefan

@Stefan171086 no workarounds, still happening, can't understand when and why. We found the issue looking into logs, but it never happened in debug or during tests.

@Stefan171086
Copy link

Stefan171086 commented Nov 30, 2023

I found the root cause of this exception in our shell app. We had a scenario where we navigate from page A to page B and because of some conditions in page B it triggered a navigation immediately back to page A. And after this immediate back navigation this exception was thrown. Now we solved our problem. May this information helps the MAUI team to fix the BUG in there code.
BR Stefan

@meierhoeferjannis
Copy link

I'm facing the same issue. I've tracked it down to fast navigation. For example, when the application starts, if you navigate to the LoginPage or the AboutPage from App.xaml.cs, depending on the authentication status, the error occurs. My current workaround is to have a default AuthenticationPage defined in the AppShell as ShellContentView. In the AuthenticationPage, I wait for a second before performing the navigation. If it helps, I can try to build a repository that reproduces the error.

@espenrl
Copy link
Contributor

espenrl commented May 28, 2024

I'm facing this one too in MAUI v8.0.40 SR5

ADB log

[ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.Maui.Controls.Platform.Compatibility.ShellToolbarTracker.get_MauiContext() in D:\a\_work\1\s\src\Controls\src\Core\Compatibility\Handlers\Shell\Android\ShellToolbarTracker.cs:line 71
   at Microsoft.Maui.Controls.Platform.Compatibility.ShellToolbarTracker.UpdateLeftBarButtonItem(Context context, Toolbar toolbar, DrawerLayout drawerLayout, Page page) in D:\a\_work\1\s\src\Controls\src\Core\Compatibility\Handlers\Shell\Android\ShellToolbarTracker.cs:line 413
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_0(Object state)
   at Android.App.SyncContext.<>c__DisplayClass2_0.<Post>b__0() in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.App/SyncContext.cs:line 36
   at Java.Lang.Thread.RunnableImplementor.Run() in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Java.Lang/Thread.cs:line 36
   at Java.Lang.IRunnableInvoker.n_Run(IntPtr jnienv, IntPtr native__this) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net8.0/android-34/mcw/Java.Lang.IRunnable.cs:line 84
   at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V(_JniMarshal_PP_V callback, IntPtr jnienv, IntPtr klazz) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:line 22

protected IMauiContext MauiContext => ShellContext.Shell.Handler.MauiContext;

I can see that UpdateLeftBarButtonItem is declared async void which possibly will run async to the caller. Perhaps this is the culprit.

protected virtual async void UpdateLeftBarButtonItem(Context context, AToolbar toolbar, DrawerLayout drawerLayout, Page page)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-controls-toolbar ToolBar platform/android 🤖 s/triaged Issue has been reviewed t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

9 participants