Akavache: Crash at System.Reactive.Linq.Observable.SelectMany
I randomly get this crash sometimes when using GetAndFetchLatest (in Xamarin.Android and Xamarin.iOS) and I can’t really see why it is happening. Any thoughts on what the reason for this can be?
Xamarin caused by: android.runtime.JavaProxyThrowable: System.ArgumentNullException: Value cannot be null. Parameter name: source at System.Reactive.Linq.Observable.SelectMany[TSource,TResult] (IObservable 1 source, System.Func 2 selector) <0xd46f6ca8 + 0x000a8> in <filename unknown>:0 at Akavache.JsonSerializationMixin.GetObject[T] (IBlobCache This, System.String key) <0xd46f60f8 + 0x0017f> in <filename unknown>:0
at Akavache.JsonSerializationMixin.GetAndFetchLatest[T] (IBlobCache This, System.String key, System.Func 1 fetchFunc, System.Func 2 fetchPredicate, Nullable 1 absoluteExpiration, Boolean shouldInvalidateOnError) <0xd46f4e58 + 0x0039b> in <filename unknown>:0
About this issue
- Original URL
- State: open
- Created 8 years ago
- Comments: 23 (4 by maintainers)
This is my take on the code to resolve this issue:
This code is in the MainActivity.OnDestroy override
I believe I am seeing the same issue. For me, the exception (System.ArgumentNullException: Value cannot be null.Parameter name: source) is a repeatable fault which occurs only after the App is resumed after being suspended. (Note: I am relatively new to X-Forms so it is entirely possible that, in my case, it is operator error)
I have attached a sample VS 2015 Xamarin Forms project (Droid only) which is failing reliably on my system. Here are the steps to reproduce.
App3.zip
Hi, same here.
Is there an alternative to static BlobCache.XXXX ? For example, we could instantiate directly an IBlobCache and keep control over that instance.
Xamarin.Forms provides us 3 events to be aware about app lifecycle : OnStart, OnResume and OnSleep, so when app is going to sleep, we can just call Flush() on the BlobCache instance for example. Or, maybe we can Dispose() the instance (or Shutdown it ?), then re-instanciating it when app resumes.
@paulcbetts Any advice about that and getting rid of BlobCache static class ?
I worked around this by moving the call to BlobCache.Shutdown().Wait(); within the OnDestroy of my main activity, rather than OnStop.