2

I've been struggling with this for 4 hours now and I'm now turning in circles. I'm trying to get Akavache to run for my project. The project is a out-of-the-box Xamarin Forms (Portable) type. Then using Nuget I added Akavache 4.1.2 (which also added Akavache Core and SqlLite3 as well as ReactiveUI and Splat). I then updated Splat because the dependency in the nuget package is wrong (was 1.3.3 but should have been 1.6.0). But still I'm getting an error launching this app (targeting iOS for now) when adding the first line that you should have to target this (BlobCache.ApplicationName = "MyApp"):

System.TypeInitializationException: The type initializer for 'Akavache.BlobCache' threw an exception. ---> System.Exception: Failed to initialize Akavache properly. Do you have a reference to Akavache.dll?
at Akavache.Sqlite3.Registrations.Register (IMutableDependencyResolver resolver) [0x0001f] in <filename unknown>:0 
at Akavache.DependencyResolverMixin.InitializeAkavache (IMutableDependencyResolver This) [0x000c0] in <filename unknown>:0 
at Akavache.BlobCache.<.cctor>b__0 () [0x0000d] in <filename unknown>:0 
at Splat.Locator.RegisterResolverCallbackChanged (System.Action callback) [0x00039] in <filename unknown>:0 
at Akavache.BlobCache..cctor () [0x00018] in <filename unknown>:0 

PS Running VS 2015 Community with Xamarin 4.1.0

Peter Donker
  • 328
  • 2
  • 15

1 Answers1

5

While not explicitly mentioned in the documentation of Akavache, normally it is required to install NuGet packages not only on your PCL but also on your platform specific projects.

This is mostly due to platform specific implementations that are needed. So although you are installing the same DLL another actual DLL - specifically for that platform - is added.

In some cases it is needed to do some sort of initialise call in the platform-specific project, although this does not seem to be the case here.

Gerald Versluis
  • 30,492
  • 6
  • 73
  • 100
  • Thanks. That seems to be the missing key. For others: The platform specific projects use Xamarin's own component store and disbles Nuget. And the component store doesn't know about Akavache. So you need to manually add a reference in the iOS project (i.e. on the references node from the solution) to \packages\akavache.core.4.1.2\lib\Xamarin.iOS10\Akavache.dll – Peter Donker Jun 17 '16 at 13:54
  • Glad to help! But I'm not sure what you mean with the 'disables NuGet' part. You can install NuGet packages on your platform projects no different than on any other kind of project. – Gerald Versluis Jun 17 '16 at 13:57
  • 1
    I stand corrected. It didn't seem to do this before but now NuGet appears to work again. – Peter Donker Jun 17 '16 at 14:43
  • Having the same issue here trying to add Akavache 4.1.2. Have added Akavache package to both my shared library and my Android project. Checked that each have a reference added to Akavache.dll in the references but still getting the 'failed to initialize' error. Any ideas? – Richard Edwards Oct 26 '16 at 16:13
  • Could you please supply me with the exact error message? Maybe it's more effective through some other media, check my profile – Gerald Versluis Oct 26 '16 at 16:21
  • 2
    I figured out my particular issue. I was calling Akavache.BlobCache.ApplicationName = "blah" before the App was initialized – Richard Edwards Oct 26 '16 at 19:33
  • @RichardEdwards I added in OnStart() method of app.cs, but i am still getting this exception. I have package installed for all projects. I believe OnStart is already after app is initialized, isnt it? – Emil Dec 29 '16 at 10:53
  • I tried every where in app.cs, mainactivity.cs. always the same error. please help. i cant find any sample project. – Emil Dec 29 '16 at 11:44
  • @batmaci I ended up putting it in the OnCreate method of MainActivity.cs after the application is loaded. – Richard Edwards Dec 30 '16 at 15:23
  • 1
    @RichardEdwards actually it also work in app.cs of PCL project. I read somewhere that sometimes nuget packages dont get installed correctly and OP was suggesting to install akavache sqlite3 package first and then akavache package. I removed all installed akavache package and followed this suggestion and it works like a charm – Emil Dec 31 '16 at 00:40