Xamarin.Forms icon indicating copy to clipboard operation
Xamarin.Forms copied to clipboard

[Bug] Xamarin forms android throw null exception after updating Xamarin forms to 5.0.0.2401

Open DevarajSekar opened this issue 2 years ago • 25 comments

While trying to open camera using Xamarin Android Camera2 API, the app getting crash.

Expected Behavior

Open Camera without any crash

Code Snippet

//Camera2 API Android cameraManager.OpenCamera(cameraId, mStateCallback, null);

Actual Behavior

App getting crash

Basic Information

  • Version with issue:
  • Last known good version:
  • Platform Target Frameworks: Android, Target SDK version 29
    • Android: 29
  • Android Support Library / AndroidX Version: Android X latest
  • NuGet Packages: Xamarin Forms 5.0.0.2401
  • Affected Devices: Nokia G21 / Redmi devices

Environment

Visual Studio 2022

Build Logs

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)

DevarajSekar avatar May 05 '22 06:05 DevarajSekar

Hey there, thanks for the report, it would be great if you could get us a little reproduction of this issue. The information here is a bit thin to go on and will make it harder to diagnose a potential issue.

jfversluis avatar May 10 '22 13:05 jfversluis

I can confirm this is happening in our project too after updating to Xamarin.Forms Version 5.0.0.2401. only in our case it occurs randomly when opening pages

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_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 at (wrapper native-to-managed) Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V(intptr,intptr)

Kemorave avatar May 24 '22 14:05 Kemorave

Google matched the exception listed here while I was looking for information on an error I am having when I add:

<skia:SKCanvasView x:Name="canvasView" PaintSurface="OnCanvasViewPaintSurface" />

to a Content page in a Xamarin solution. Here's the output:

[zygote64] JIT allocated 71KB for compiled code of void android.widget.TextView.<init>(android.content.Context, android.util.AttributeSet, int, int)
[zygote64] Compiler allocated 8MB to compile void android.widget.TextView.<init>(android.content.Context, android.util.AttributeSet, int, int)
[] HostConnection::get() New Host Connection established 0x7b742b6abb40, tid 9620
[OpenGLRenderer] Initialized EGL, version 1.4
[OpenGLRenderer] Swap behavior 1
[EGL_emulation] eglCreateContext: 0x7b743ca376e0: maj 3 min 0 rcv 3
[EGL_emulation] eglMakeCurrent: 0x7b743ca376e0: ver 3 0 (tinfo 0x7b742b6b0c60)
**System.NullReferenceException:** 'Object reference not set to an instance of an object.'
Thread finished: <Thread Pool> #5
[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_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 
[mono-rt]   at (wrapper native-to-managed) Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPL_V(intptr,intptr,intptr)
[] HostConnection::get() New Host Connection established 0x7b74281c2740, tid 9588

I am using Visual Studio 2022 with the x86_64 emulator. I was under the impression it was an issue with SkiaSharp/OpenGL though?

Sl0thie avatar Jun 01 '22 00:06 Sl0thie

Hello,

Also, google linked me here searching for the bwlo error from the Mono RT.

I am able to reproduce this with a a new Shell Content that has 3 pages. First page, has a set of buttons, 2nd, the Camera2 view, and third another list of settings. When navigating the first time to the 'Camera2' page, it seems fine. But then going back to first, then again to the Camera2 page, this exception is consistently always being thrown now.

However, this also occurs from going back and forth between page 1 and 3, so not the page with the Camera2 control on it...

[View] requestLayout() improperly called by crc64f72ebd847d591cfa.ContentContainer{fb6515 VFE...... ......ID 0,108-2560,1150} during layout: running second layout pass
**System.NullReferenceException:** 'Object reference not set to an instance of an object.'

[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)

Running Xamarin Forms 5.0.0.2337 Same Behaviour when updated to XForms 5.0.0.2401 Visual Studio 2022 17.2.2 Upgraded to VS 2022 17.2.3 Same Errors...

Updated 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 ?

zerokewl88 avatar Jun 07 '22 07:06 zerokewl88

I sometimes have the same issue (same stacktrace) when navigating between pages although I can not really reproduce it at will. I am not sure what started this issue. I am not using Shell but FreshMvvm for my navigation. It seems some timing issue or something because if you move slow between the pages it is no issue.

When I Googled the error I came across this bug report so I looked into my logging and it started a day after I upgraded to XF 5.0.0.2401 so I think it might be related to this upgrade. I will go back to XF 5.0.0.2337 for now to see if it cures this issue.

Logging from appcenter:

Error: JNINativeWrapper._unhandled_exception (System.Exception e) /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs, line 12 System.NullReferenceException: Object reference not set to an instance of an object.

Stacktrace: JNINativeWrapper._unhandled_exception (System.Exception e) /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:12 JNINativeWrapper.Wrap_JniMarshal_PP_V (_JniMarshal_PP_V callback, System.IntPtr jnienv, System.IntPtr klazz) /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:23 (wrapper native-to-managed) Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V(intptr,intptr)

michelmoorlag avatar Jun 10 '22 06:06 michelmoorlag

Is anyone here also using any specific controls on this page, i'm finding that when i comment out all the UI on my page, everything works ok.

I then start to uncomment UI elements, and find the TabBar from 'clr-namespace:Syncfusion.XForms.TabView;assembly=Syncfusion.SfTabView.XForms' does start to cause issues...

zerokewl88 avatar Jun 10 '22 07:06 zerokewl88

Is anyone here also using any specific controls on this page, i'm finding that when i comment out all the UI on my page, everything works ok.

I then start to uncomment UI elements, and find the TabBar from 'clr-namespace:Syncfusion.XForms.TabView;assembly=Syncfusion.SfTabView.XForms' does start to cause issues...

Ohh that is interesting information, I am using Syncfusion controls too! Although I am not using the SfTabView I am using version 20.0.1.57 of Buttons, SfAutocomplete and SfPdfViewer. @zerokewl88 Which version of the sf controls are you using?

michelmoorlag avatar Jun 10 '22 08:06 michelmoorlag

I've just updated to their latest today, and found much more stability, and that above error is no longer there. I now am using 20.1.0.59, prior to todays' update, i was using 18.x.x.x. hahaha.. so a bit of a jump, but the upgrade worked fine and no hassles :)

zerokewl88 avatar Jun 10 '22 09:06 zerokewl88

Hmm I will upgrade to 20.1.0.59 and see if it fixes this issue. @zerokewl88 Good observations!

michelmoorlag avatar Jun 10 '22 09:06 michelmoorlag

XF 5.0.0.2478 in combination with Syncfusion 20.1.0.59 still crashes on me :( Very rare but it does with the same error

michelmoorlag avatar Jun 17 '22 10:06 michelmoorlag

Just double checked again, and my XForms, i'm using 5.0.0.2401 - this seems stable for me, yet to have it crash once. It's going out to Acceptance Testing soon, so will have more users available to try crash it. Will report back if i get a crash...

XForms 5.0.0.2401 Syncfusion 20.1.0.59

zerokewl88 avatar Jun 17 '22 10:06 zerokewl88

I'm also using image image image

zerokewl88 avatar Jun 17 '22 10:06 zerokewl88

This is an issue in the Xamarin.Android version distributed with VS 17.2 branch. All exceptions throw from Android side cause a NullReference when they get back to .NET side. It has been fixed recently by this PR https://github.com/xamarin/xamarin-android/pull/7103 I don't know if this fix will by included in the next release patch or if we will have to wait for the 17.3 branch.

In all case, if we have this issue it is caused be an exception in Android that will need to be fixed (either on Xamarin side or User code side), but for now we can't know the real cause before this fix has been released.

kvpt avatar Jun 21 '22 13:06 kvpt

@kvpt ,

Thank you for this valuable information because I was really in the dark with this issue.

The problem is that I installed the latest VS update but I need to release a new version of my app with a very important bugfix. But now I can not because it will introduce this issue to my users so I am stuck right now.

What would be the best solution to circumvent this issue until there is a fix available? The only thing I can think of is to uninstall VS and somehow download and install the latest VS 17.1 version? Is this possible or are there better solutions?

Or is this a debug problem only?

michelmoorlag avatar Jun 24 '22 06:06 michelmoorlag

Same issue as @michelmoorlag and @zerokewl88, seeing this runtime error in Xamarin.Android app with some embedded Xamarin.Forms pages (created using Page.CreateSupportFragment() method). Using the Syncfusion DataGrid.

follesoe avatar Jun 24 '22 10:06 follesoe

Any workaround?

pmahend1 avatar Jun 25 '22 16:06 pmahend1

I'm still getting this error.. 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_PPLLL_L (_JniMarshal_PPLLL_L callback, System.IntPtr jnienv, System.IntPtr klazz, System.IntPtr p0, System.IntPtr p1, System.IntPtr p2) [0x00022] in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:298 at (wrapper native-to-managed) Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPLLL_L(intptr,intptr,intptr,intptr,intptr) It would be really helpful if someone can help me out with it. it starts ShellContentFragment.OnCreateView line no 139

ssnavalakha avatar Jun 29 '22 22:06 ssnavalakha

#15452 @jfversluis

acaliaro avatar Jul 01 '22 15:07 acaliaro

Workaround for error: "[mono-rt] [ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object."

https://github.com/xamarin/xamarin-android/issues/7085#issuecomment-1153434079

xDaijobu avatar Jul 20 '22 11:07 xDaijobu

Workaround for error: "[mono-rt] [ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object."

xamarin/xamarin-android#7085 (comment)

This is not a workaround for me... added the lines of code and app still crashed

abhaylakkad avatar Aug 01 '22 11:08 abhaylakkad

Receiving following error while navigating pages on Android Emulator. Visual Studio 2022, v17.2.5 on windows. I'm Xamarin.Forms 5.0.2401 also tried 2515 but same error.

System.NullReferenceException: Object reference not set to an instance of an object.

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_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 at (wrapper native-to-managed) Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V(intptr,intptr)

Anyone found any work around ?

abhaylakkad avatar Aug 01 '22 11:08 abhaylakkad

Receiving this error as well on Android. VS 2022, v17.2.6 on Windows, Xamarin Forms v5.00.2337

System.NullReferenceException: 'Object reference not set to an instance of an object.'

[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)

Any workaround yet?

EthanCopeland avatar Aug 05 '22 08:08 EthanCopeland

Receiving this error as well on Android. VS 2022, v17.2.6 on Windows, Xamarin Forms v5.00.2337

System.NullReferenceException: 'Object reference not set to an instance of an object.'

[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)

Any workaround yet?

This is what you can try -

  1. Update your Visual Studio on 17.3 thru preview channel
  2. Once updated you will get the exact error. OR if you are using List View .. then simply add CachingStrategy = "RecycleElement" and see if error resolved..

Actually, I was having same issue... The error is was something different and Android throwing JNINavtiveWrapper exception. I was using the ListView on page and i have to add - CachingStrategy = "RecycleElement" to list view..

abhaylakkad avatar Aug 05 '22 09:08 abhaylakkad

Hi, anyone who solve or have a work around on this?

im having the same issue

00elan avatar Sep 05 '22 05:09 00elan

In theory the fix is included in the latest Xamarin Android version shipped with Visual Studio 17.3 branch. On my side, I have not encountered NullReferenceException since the update. If you still have the issue after the Visual Studio update, try to uninstall your app from the device and reploy it to force the latest runtime version to be used.

kvpt avatar Sep 05 '22 11:09 kvpt

What a problem...

chaoyebugao avatar Sep 27 '22 03:09 chaoyebugao