Essentials: [Bug] NullReferenceException is thrown after CapturePhotoAsync

Created on 28 Sep 2020  Â·  13Comments  Â·  Source: xamarin/Essentials

Description

A NullReferenceException is thrown after taking a picture with CapturePhotoAsync. The camera app is shown, a picture can be taken. But after accepting the picture the error occurs.

Steps to Reproduce

  1. Take a picture
  2. Accept the picture
  3. NullReferenceException is thrown from Xamarin.Essentials

09-28 09:30:51.173 I/MonoDroid( 2663): UNHANDLED EXCEPTION:
09-28 09:30:51.175 I/MonoDroid( 2663): System.NullReferenceException: Object reference not set to an instance of an object.
09-28 09:30:51.175 I/MonoDroid( 2663): at Xamarin.Essentials.IntermediateActivity.OnActivityResult (System.Int32 requestCode, Android.App.Result resultCode, Android.Content.Intent data) [0x00041] in D:\a\1\s\Xamarin.Essentials\Platform\Platform.android.cs:458
09-28 09:30:51.175 I/MonoDroid( 2663): at Android.App.Activity.n_OnActivityResult_IILandroid_content_Intent_ (System.IntPtr jnienv, System.IntPtr native__this, System.Int32 requestCode, System.Int32 native_resultCode, System.IntPtr native_data) [0x00013] in /Users/builder/azdo/_work/287/s/xamarin-android/src/Mono.Android/obj/Release/monoandroid10/android-28/mcw/Android.App.Activity.cs:2373
09-28 09:30:51.175 I/MonoDroid( 2663): at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.8(intptr,intptr,int,int,intptr)

Expected Behavior

Picture is selected without exception

Actual Behavior

NullReferenceException is thrown.

Basic Information

  • Version with issue: 1.6.0-pre2
  • Last known good version: NA
  • IDE: Visual Studio 2019
  • Platform Target Frameworks:

    • iOS: NA

    • Android: Android 10.0

    • UWP: NA

  • Android Support Library Version: NA
  • Nuget Packages:
  • Affected Devices: Motorola AOSP on shama (Android 5.1 - API 22) (on nox emulator)

Screenshots

Reproduction Link

bug

Most helpful comment

I pushed the PR build to the preview feed so hopefully there can be a test.

Feed: https://aka.ms/xamarin-essentials-ci/index.json
Version: 1.6.0-pr.1480.1

All 13 comments

Just checking the Android versions... Is this happening on Android 10 or 5.1 or both? Does it work on the emulator or device or neither?

This is happening on the 5.1 nox emulator, which emulates that device.

Op ma 28 sep. 2020 om 21:17 schreef Matthew Leibowitz <
[email protected]>:

Just checking the Android versions... Is this happening on Android 10 or
5.1 or both? Does it work on the emulator or device or neither?

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/xamarin/Essentials/issues/1397#issuecomment-700229901,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ARFLX3OFHW6PW7DVDFXKHRTSIDOMHANCNFSM4R4F5N5Q
.

Did you test on an actual device, or the traditional emulator at all? Just trying to get a baseline here.

Only the nox emulator. I can try an actual device tomorrow if you'd like.

Op ma 28 sep. 2020 om 21:35 schreef Matthew Leibowitz <
[email protected]>:

Did you test on an actual device, or the traditional emulator at all? Just
trying to get a baseline here.

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/xamarin/Essentials/issues/1397#issuecomment-700238183,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ARFLX3IZWGMWXVBDDFRDHWDSIDQOHANCNFSM4R4F5N5Q
.

But since my physical device is android 10 I don't expect a problem there
honestly.
However, we have to support 4.4 and up. I know at least one other person
had the same issue.

Op ma 28 sep. 2020 om 21:55 schreef Peter Thielen peterthln@gmail.com:

Only the nox emulator. I can try an actual device tomorrow if you'd like.

Op ma 28 sep. 2020 om 21:35 schreef Matthew Leibowitz <
[email protected]>:

Did you test on an actual device, or the traditional emulator at all?
Just trying to get a baseline here.

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/xamarin/Essentials/issues/1397#issuecomment-700238183,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ARFLX3IZWGMWXVBDDFRDHWDSIDQOHANCNFSM4R4F5N5Q
.

OK, thanks for the info. I'll check it out and see what is up.

I also got this issue when i run my app on device to take photo from camera (my device nougat 7.1)

The issue also occurs in a device running Android 9.0 (API 28)

Same issue on Android 10

OnActivityResult seems to receive null for the data Intent. This is due to a camera manufactor inconsistency. Some manufacturers require a preinserted uri, and if this is present they may call OnActivityResult with a null intent. I believe I have a workaround but I dont have a device to trigger it. Replace OnActivityResult in Platform.android.cs with this Gist.

I am using android 9 physical device. I am getting this exception after saving captured image.

UNHANDLED EXCEPTION:
10-14 13:27:17.041 I/MonoDroid( 2983): System.NullReferenceException: Object reference not set to an instance of an object.
10-14 13:27:17.042 I/MonoDroid( 2983): at Xamarin.Essentials.IntermediateActivity.OnActivityResult (System.Int32 requestCode, Android.App.Result resultCode, Android.Content.Intent data) [0x00041] in D:\a\1\s\Xamarin.Essentials\Platform\Platform.android.cs:458
10-14 13:27:17.042 I/MonoDroid( 2983): at Android.App.Activity.n_OnActivityResult_IILandroid_content_Intent_ (System.IntPtr jnienv, System.IntPtr native__this, System.Int32 requestCode, System.Int32 native_resultCode, System.IntPtr native_data) [0x00012] in <9a14097a65a445eaa85f6a3a1ade52a3>:0
10-14 13:27:17.042 I/MonoDroid( 2983): at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.7(intptr,intptr,int,int,intptr)
10-14 13:27:17.067 D/Mono ( 2983): DllImport searching in: '__Internal' ('(null)').
10-14 13:27:17.067 D/Mono ( 2983): Searching for 'java_interop_jnienv_throw'.
10-14 13:27:17.067 D/Mono ( 2983): Probing 'java_interop_jnienv_throw'.
10-14 13:27:17.068 D/Mono ( 2983): Found as 'java_interop_jnienv_throw'.
System.NullReferenceException: 'Object reference not set to an instance of an object.'

Thanks @Mrnikbobjeff for that investigation. I'll create a PR and see if we can get testing.

I pushed the PR build to the preview feed so hopefully there can be a test.

Feed: https://aka.ms/xamarin-essentials-ci/index.json
Version: 1.6.0-pr.1480.1

Was this page helpful?
0 / 5 - 0 ratings