1

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);

            }
        }
  • According to this [issue](https://github.com/reactiveui/Akavache/issues/635), it seems like a bug of the akavache. So you can try to post it to the akavache's developer on the github – Liyun Zhang - MSFT Mar 11 '22 at 05:33
  • I ended up using Monkey Cache: https://github.com/jamesmontemagno/monkey-cache, its a very simple cache manager and perfect for what I needed, not async however – Christopher Heeley Mar 17 '22 at 17:02

0 Answers0