'Xamarin.Android Akavache throwing System.InvalidOperationException
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);
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
