-
Notifications
You must be signed in to change notification settings - Fork 505
[Bug] [Crash] Unable to activate instance of type Xamarin.Essentials.MagnetometerListener #1272
Comments
When you are using this API are you wrapping it in a try/catch? Looks like this is only on some devices, not all correct. Not every device supports all sensors and an exception will be thrown as you can see in the logs: NotSupportedException which is expected. |
I will wrap it in try/catch, but we also check whether a device is supported before starting a magnetometer.
It shouldn't say that constructor not found if device is simply not supported |
Just checked again - yes, its' wrapped in a try/catch block |
@jonathanpeppers thoughts on this? I am looking through: https://docs.microsoft.com/en-us/xamarin/android/internals/architecture#managed-callable-wrapper-subclasses |
The way this error generally happens:
Usually, it means there is some "unsubscribe" call that Java needs so it won't call again. Looking at the code, it seems like the Essentials/Xamarin.Essentials/Magnetometer/Magnetometer.android.cs Lines 28 to 30 in 9e74d1c
Does this crash only happen after leaving your |
@jonathanpeppers |
@bohdant Are you stopping and re-starting Magnetometer frequently? I think in this case a callback to |
Description
Android Apps are crashing: Unable to activate instance of type Xamarin.Essentials.MagnetometerListener from native handle
Stack Trace
Fatal Exception: android.runtime.JavaProxyThrowable: System.NotSupportedException: Unable to activate instance of type Xamarin.Essentials.MagnetometerListener from native handle 0xffe2681c (key_handle 0x87af207). ---> System.MissingMethodException: No constructor found for Xamarin.Essentials.MagnetometerListener::.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) [0x00055] in <378795aacbfc41c3b0db0fba208eeb1e>:0
at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) [0x00116] in <378795aacbfc41c3b0db0fba208eeb1e>:0
--- End of inner exception stack trace ---
at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) [0x00182] in <378795aacbfc41c3b0db0fba208eeb1e>:0
at Java.Lang.Object.GetObject (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type type) [0x000c1] in <378795aacbfc41c3b0db0fba208eeb1e>:0
at Java.Lang.Object.GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00017] in <378795aacbfc41c3b0db0fba208eeb1e>:0
at Java.Lang.Object.GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00000] in <378795aacbfc41c3b0db0fba208eeb1e>:0
at Java.Lang.Object.GetObject[T] (System.IntPtr jnienv, System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00006] in <378795aacbfc41c3b0db0fba208eeb1e>:0
at Android.Hardware.ISensorEventListenerInvoker.n_OnSensorChanged_Landroid_hardware_SensorEvent (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_e) [0x00000] in <378795aacbfc41c3b0db0fba208eeb1e>:0
at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.29(intptr,intptr,intptr)
at crc64a0e0a82d0db9a07d.MagnetometerListener.n_onSensorChanged(MagnetometerListener.java)
at crc64a0e0a82d0db9a07d.MagnetometerListener.onSensorChanged(MagnetometerListener.java:39)
at android.hardware.SystemSensorManager$SensorEventQueue.dispatchSensorEvent(SystemSensorManager.java:981)
at android.os.MessageQueue.nativePollOnce(MessageQueue.java)
at android.os.MessageQueue.next(MessageQueue.java:326)
at android.os.Looper.loop(Looper.java:181)
at android.app.ActivityThread.main(ActivityThread.java:7077)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964)
Steps to Reproduce
Can't figure out correlation, when the bug occurs
Expected Behavior
App doesn't crashes
Actual Behavior
App crashes
Basic Information
61% Android 9
34% Android 10
5% Android 8
Screenshots
Reproduction Link
The text was updated successfully, but these errors were encountered: