Xamarin forms android throw null exception after updating Xamarin forms to 5.0.0.2401

Viewed 1695

I have updated Xamarin Forms to latest version(5.0.0.2401). It is working fine in iOS. In android first it returns Error: Could not find 2 Android X assemblies, make sure to install the following NuGet packages: - Xamarin.AndroidX.MediaRouter, Xamarin.AndroidX.Palette. After that I have added these 2 packages. Now It will debug without error but it does not deploy in android. It returns System.NullReferenceException has been thrown Object reference not set to an instance of an object error and in stack trace it returns the following error.

at Android.Runtime.JNINativeWrapper._unhandled_exception (System.Exception e) [0x0000e] in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:12 at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPL_V (_JniMarshal_PPL_V callback, System.IntPtr jnienv, System.IntPtr klazz, System.IntPtr p0) [0x0001d] in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:111 at (wrapper native-to-managed) Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPL_V(intptr,intptr,intptr).

Target Android version - v10.0

Please help to fix this issue.

2 Answers

I am facing a similar issue with Camera2, and i can see the following in the output debug console when shifting between pages that have the control and then trying to navigate to another page.

I find that if i'm slow in my user actions, the app seems stable. Although, if i rush and navigate quickly, the app does crash with the following.

After changing pages this appears in the Debug Console.

[MessageQueue] Handler (android.os.Handler) {e7ad8fd} sending message to a Handler on a dead thread
[MessageQueue] java.lang.IllegalStateException: Handler (android.os.Handler) {e7ad8fd} sending message to a Handler on a dead thread
[MessageQueue]  at android.os.MessageQueue.enqueueMessage(MessageQueue.java:560)
[MessageQueue]  at android.os.Handler.enqueueMessage(Handler.java:778)
[MessageQueue]  at android.os.Handler.sendMessageAtTime(Handler.java:727)
[MessageQueue]  at android.os.Handler.sendMessageDelayed(Handler.java:697)
[MessageQueue]  at android.os.Handler.post(Handler.java:427)
[MessageQueue]  at android.hardware.camera2.impl.CameraDeviceImpl$CameraHandlerExecutor.execute(CameraDeviceImpl.java:2302)
[MessageQueue]  at android.hardware.camera2.impl.CallbackProxies$SessionStateCallbackProxy.onClosed(CallbackProxies.java:104)
[MessageQueue]  at android.hardware.camera2.impl.CameraCaptureSessionImpl.close(CameraCaptureSessionImpl.java:588)
[MessageQueue]  at android.hardware.camera2.impl.CameraCaptureSessionImpl.finalize(CameraCaptureSessionImpl.java:879)
[MessageQueue]  at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:291)
[MessageQueue]  at java.lang.Daemons$FinalizerDaemon.runInternal(Daemons.java:278)
[MessageQueue]  at java.lang.Daemons$Daemon.run(Daemons.java:139)
[MessageQueue]  at java.lang.Thread.run(Thread.java:920)

This appears after crashing and attempting to load between Shell Pages quickly..

[OpenGLRenderer] Davey! duration=1323ms; Flags=0, FrameTimelineVsyncId=1360448, IntendedVsync=100388678577668, Vsync=100389828577622, InputEventId=0, HandleInputStart=100389841897744, AnimationStart=100389841906130, PerformTraversalsStart=100389842887067, DrawStart=100389992949619, FrameDeadline=100388695244334, FrameInterval=100389841589150, FrameStartTime=16666666, SyncQueued=100389996757588, SyncStart=100389997235609, IssueDrawCommandsStart=100389997569046, SwapBuffers=100389999503421, FrameCompleted=100390002199567, DequeueBufferDuration=29323, QueueBufferDuration=1906198, GpuCompleted=100390001411286, SwapBuffersCompleted=100390002199567, DisplayPresentTime=64544768526125, 
**System.NullReferenceException:** 'Object reference not set to an instance of an object.'

Thread finished: <Thread Pool> #2
The thread 0x2 has exited with code 0 (0x0).
Thread started: <Thread Pool> #38
[mono-rt] [ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object.
[mono-rt]   at Android.Runtime.JNINativeWrapper._unhandled_exception (System.Exception e) [0x0000e] in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:12 
[mono-rt]   at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V (_JniMarshal_PP_V callback, System.IntPtr jnienv, System.IntPtr klazz) [0x0001c] in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:23 
[mono-rt]   at (wrapper native-to-managed) Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V(intptr,intptr)
[BpBinder] onLastStrongRef automatically unlinking death recipients: <uncached descriptor>
[BpBinder] onLastStrongRef automatically unlinking death recipients: <uncached descriptor>

Using Visual Studio 17.2.3 Xamarin Forms 5.0.0.2401

This was stable a few weeks ago, and something i tried to change was the AppShell Layout, from using

<TabBar>
<Tab>
        <ShellContent ... />
        <ShellContent ... />
        <ShellContent ... />
</Tab>
</TabBar>

to

<TabBar>
<ShellContent ... />
<ShellContent ... />
<ShellContent ... />
</TabBar>

It's strange, but the app i can navigate quickly between pages now and it seems almost stable, while testing now, it's more rare that it crashes with the same error, than before. Is this a rendering issue of some sort ?

If you are using Visual Studio 2022 preview then update the following setting:

  1. Right-click on the Android project and select properties.
  2. Select Android options.
  3. Check the Use Fast Deployment (debug mode only)

Screenshot: enter image description here

Related