sameerkapps / SecureStorage

118 stars 32 forks source link

System.ArgumentException: Handle must be valid. Parameter name: instance on CrossSecureStorage #51

Open HadiHas opened 4 years ago

HadiHas commented 4 years ago

Lately the xamarin android app is crashing randomly on CrossSecureStoragewith error as below:

public static string CrossSecureUserTypeKey { get; } = "UserType"; //Located in Statics.cs var UserType = Plugin.SecureStorage.CrossSecureStorage.Current.GetValue(Statics.CrossSecureUserTypeKey);

Error:

System.ArgumentException: Handle must be valid. Parameter name: type at Java.Interop.JniEnvironment+InstanceMethods.GetMethodID (Java.Interop.JniObjectReference type, System.String name, System.String signature) [0x00009] in :0 at Android.Runtime.JNIEnv.GetMethodID (System.IntPtr kls, System.String name, System.String signature) [0x00007] in :0 at Android.Content.ISharedPreferencesInvoker.Contains (System.String key) [0x00012] in :0 at Plugin.SecureStorage.SecureStorage.HasKey (System.String key) [0x0000d] in :0 at drappme.MainActivity.b__40_0 () [0x00018]

any thoughts?

bohdan-sobko commented 4 years ago

+1

I have a similar problem. @sameerkapps Any ideas about root cause / how to fix it? Thank you.

Galaxy S7 Android 8.0.0 Galaxy XCover4 Android 8.1.0

1) AndroidKeyStoreImplementation.GetValue (System.String key, System.String defaultValue) System.ArgumentException: Handle must be valid. Parameter name: type ...

JniEnvironment+InstanceMethods.GetMethodID (Java.Interop.JniObjectReference type, System.String name, System.String signature)
JNIEnv.GetMethodID (System.IntPtr kls, System.String name, System.String signature)
ISharedPreferencesInvoker.GetString (System.String key, System.String defValue)
AndroidKeyStoreImplementation.GetValue (System.String key, System.String defaultValue)
SecureStorageImplementation.GetValue (System.String key, System.String defaultValue)
SecureStore.GetValue (System.String key)

2) AndroidKeyStoreImplementation.GetValue (System.String key, System.String defaultValue) System.ArgumentException: Handle must be valid. Parameter name: instance ...

JniEnvironment+InstanceMethods.CallObjectMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args)
JNIEnv.CallObjectMethod (System.IntPtr jobject, System.IntPtr jmethod, Android.Runtime.JValue* parms)
ISharedPreferencesInvoker.GetString (System.String key, System.String defValue)
AndroidKeyStoreImplementation.GetValue (System.String key, System.String defaultValue)
SecureStorageImplementation.GetValue (System.String key, System.String defaultValue)
SecureStore.GetValue (System.String key)
bohdanhrybach commented 4 years ago

+1 @sameerkapps Probably need fix made in Xamarin.Essentials: https://github.com/xamarin/Essentials/pull/386/files#diff-57e97505a71d3732c6a7bf3fc654764e