Akavache icon indicating copy to clipboard operation
Akavache copied to clipboard

[BUG] Android- Blobcache sometimes null. why or how to handle it?

Open EmilAlipiev opened this issue 5 years ago • 2 comments

Describe the bug I am seeing regularly below exception in my exception logs.

JsonSerializationMixin.GetObject[T] (Akavache.IBlobCache This, System.String key)
System.ArgumentNullException: Value cannot be null. Parameter name: source

at System.Reactive.Linq.Observable.SelectMany[TSource,TResult] (System.IObservable`1[T] source, System.Func`2[T,TResult] selector) <0x7c91370e34 + 0x000e0> in <11c0ec0fa99843708cbf96b5e08890cd>:0 \n  at Akavache.JsonSerializationMixin.GetObject[T] (Akavache.IBlobCache This, System.String key)

I am not sure why it is occurring but it seems that maybe BlobCache is null according to the source code, if i am reading it correct.

 public static IObservable<T> GetObject<T>(this IBlobCache blobCache, string key)
        {
            if (blobCache is null)
            {
                throw new ArgumentNullException(nameof(blobCache));
            }

            if (blobCache is IObjectBlobCache objCache)
            {
                return objCache.GetObject<T>(key);
            }

            return blobCache.Get(GetTypePrefixedKey(key, typeof(T))).SelectMany(DeserializeObject<T>);
        }

If thats the case in what cases it maybe null ? I initialize akavache right inside the App.cs Constructor as

            Akavache.BlobCache.ApplicationName = "myCache";
            Akavache.BlobCache.EnsureInitialized();

and I only use Shutdown in Ondestroy

   protected override void OnDestroy()
        {         
                base.OnDestroy();
                Akavache.BlobCache.Shutdown().Wait();  // this calls the shutdown code
                Akavache.BlobCache.UserAccount = null; // clear out the static cached variables
 }
 

If that is so far fine what could be the reason BlobCache is null after initialized?

EmilAlipiev avatar Jan 04 '21 00:01 EmilAlipiev

I want to go through Akavache and give it some love soon. I'll look into your exception then.

glennawatson avatar Jan 04 '21 00:01 glennawatson

The same thing happens to some users of my Android application...

angelru avatar Jan 25 '22 08:01 angelru