VS bug #1140617
Cross-referencing note for the Xamarin team
There is a matching Developer Community item reported against Xamarin.Android 10.3.99.259 (d16-7) in Visual Studio 2019 version 16.7 Preview 2: https://developercommunity.visualstudio.com/content/problem/1071004/vs-1670-preview-2-sparcearray-notsupportedexceptio.html
@wuhuangjia can you attach a simple project which triggers the problem for you? Thanks!
@wuhuangjia can you attach a simple project which triggers the problem for you? Thanks!
ok, will try to make a sample, thanks a lot
should be the same issue
https://github.com/JimmyPun610/BarcodeScanner.XF/issues/37
Thanks for the note about the BarcodeScanner.XF sample app! I was able to reproduce the problem with that sample using the following steps:
cmd
msbuild -restore -t:Install SampleApp\SampleApp.Android\SampleApp.Android.csproj
_Result:_
Shortly after the the new view opens and the screen starts showing an image from the camera, the app encounters the unhandled exception:
System.NotSupportedException: Unable to activate instance of type Android.Util.SparseArray`1[E] from native handle 0x19 (key_handle 0x547ad98). ---> System.MissingMethodException: No constructor found for Android.Util.SparseArray`1::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership) ---> Java.Interop.JavaLocationException: Exception of type 'Java.Interop.JavaLocationException' was thrown.
--- End of inner exception stack trace ---
at Java.Interop.TypeManager.CreateProxy (System.Type type, System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x000b5] in <43cddc76fe22432dbdbcea2397b6fcd7>:0
at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) [0x00111] in <43cddc76fe22432dbdbcea2397b6fcd7>:0
--- End of inner exception stack trace ---
at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) [0x0017e] in <43cddc76fe22432dbdbcea2397b6fcd7>:0
at Java.Lang.Object.GetObject (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type type) [0x00023] in <43cddc76fe22432dbdbcea2397b6fcd7>:0
at Java.Lang.Object._GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00017] in <43cddc76fe22432dbdbcea2397b6fcd7>:0
at Java.Lang.Object.GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00000] in <43cddc76fe22432dbdbcea2397b6fcd7>:0
at Android.Gms.Vision.Detector+Detections.get_DetectedItems () [0x0001f] in <ef7fc227a7e44020bc62e1ade21588fd>:0
at GoogleVisionBarCodeScanner.Droid.CameraPreview+DetectorProcessor.ReceiveDetections (Android.Gms.Vision.Detector+Detections detections) [0x00001] in <41132494451344bebfd47921df020acc>:0
at Android.Gms.Vision.Detector+IProcessorInvoker.n_ReceiveDetections_Lcom_google_android_gms_vision_Detector_Detections_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_detections) [0x0000f] in <ef7fc227a7e44020bc62e1ade21588fd>:0
at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.63(intptr,intptr,intptr)
_Notes:_
As JimmyPun610 found, this problem is fairly dependent on the particular set of assemblies and versions of assemblies used in an app, so in some cases, changing the target framework version of the app or updating NuGet packages might help avoid the issue, but it looks like this issue will need a fix in Xamarin.Android.
_Cross-referencing note for the Xamarin team:_
This issue might have same underlying cause as https://github.com/xamarin/xamarin-android/issues/4809.
_Version information:_
The issue also occurs with Visual Studio 2019 version 16.7 Preview 2:
Testing device: arm64-v8a Android 9.0 Pie (API level 28) Google Pixel 3
One other result I should mention to be thorough is that like
in https://github.com/xamarin/xamarin-android/issues/4809, I was only able to reproduce the exception for Android.Util.SparseArray`1[E] in the Debug configuration, which uses the debug version of _libmonodroid.so_ and a different approach to typemaps than the Release configuration.
Although this additional result isn't especially helpful for the development scenario, it means there is a margin of safety for the final app publication scenario in the Release configuration.
_Status update_
A candidate fix for this issue has been added to the xamarin-android/d16-7 development branch in https://github.com/xamarin/xamarin-android/commit/bb0f7ebeb12fd6abadafa6b4c9a3db318fb93183. This change is not yet available in a published version. I will update this item again when a published version is available that includes the fix.
_Fix verification_
Fix verified. Using a development build that includes the fix, I retested the steps to reproduce from before. I verified that I could no longer reproduce the problem with the development version and confirmed that the problem reappeared if I switched back the current published versions of Xamarin.Android.
Development build tested: Xamarin.Android SDK version 11.0.0.1 (d16-7@17cc49e)
This problem happens to me ONLY after using a splash screen and moving Xamarin initializations to Splash activity, but disappeared when setting Linker Properties Linking to Sdk Assemblies Only
_Release status update_
A new Preview version of Xamarin.Android has now been published that includes the fix for this item. The fix is not yet included in a Release version. I will update this again when a Release version is available that includes the fix.
Fix included in Xamarin.Android 11.0.0.3.
Fix included on Windows in Visual Studio 2019 version 16.7 Preview 4. To try the Preview version that includes the fix, check for the latest updates in Visual Studio Preview.
Fix included on macOS in Visual Studio 2019 for Mac version 8.7 Preview 4. To try the Preview version that includes the fix, check for the latest updates on the Preview updater channel.
_Release status update_
A new Release version of Xamarin.Android has now been published that includes the fix for this issue.
Fix included in Xamarin.Android SDK version 11.0.0.3.
Fix included on Windows in Visual Studio 2019 version 16.7. To get the new version that includes the fix, check for the latest updates or install the most recent release from https://visualstudio.microsoft.com/downloads/.
Fix included on macOS in Visual Studio 2019 for Mac version 8.7. To get the new version that includes the fix, check for the latest updates on the Stable updater channel.
Most helpful comment
_Status update_
A candidate fix for this issue has been added to the xamarin-android/d16-7 development branch in https://github.com/xamarin/xamarin-android/commit/bb0f7ebeb12fd6abadafa6b4c9a3db318fb93183. This change is not yet available in a published version. I will update this item again when a published version is available that includes the fix.
_Fix verification_
Fix verified. Using a development build that includes the fix, I retested the steps to reproduce from before. I verified that I could no longer reproduce the problem with the development version and confirmed that the problem reappeared if I switched back the current published versions of Xamarin.Android.
Development build tested: Xamarin.Android SDK version 11.0.0.1 (d16-7@17cc49e)