Xamarin.Android Akavache throwing System.InvalidOperationException

108 views Asked by At

I am creating a XamarinAndroid application, on one activity my akavache works perfectly fine, inserting / removing objects.

On another activity Akavache keeps returning this Exception:

System.InvalidOperationException:** 'Sequence contains no elements

This is mostly when I try to remove an object, here is the code that throws the exception

Removing:
        private async void BtnLogout_Click(object sender, EventArgs e)
        {
            await BlobCache.UserAccount.Invalidate("authCurrentUser");
            StartActivity(typeof(Login));
        }
Getting:
        public async Task<AuthCurrentUser> getCurrentAuthUser()
        {
            try
            {
                AuthCurrentUser result = await BlobCache.UserAccount.GetObject<AuthCurrentUser>("authCurrentUser");
                return result;
            }
            catch (KeyNotFoundException ex)
            {
                return new AuthCurrentUser();
            }
        }
Setting:
        public async Task setCurrentAuthUser(AuthCurrentUser AuthCurrentUser)
        {
            if (AuthCurrentUser != null)
            {
                System.Diagnostics.Debug.WriteLine(AuthCurrentUser.userName + "sCAU");

                BlobCache.EnsureInitialized();
                await BlobCache.UserAccount.Invalidate("authCurrentUser");

                await BlobCache.UserAccount.InsertObject("authCurrentUser", AuthCurrentUser);

            }
        }
0

There are 0 answers