I’m trying to use Couchbase.Lite in a Xamarin.Forms app but runnig up against a System.TypeInitializationException when I try to create/get the database using this code:
// Get the database (and create it if it doesn't exist)
var database = new Database("mydb");
I have the Couchbase.Lite NuGet package installed in all my projects and I am calling the Activate method in my Android MainActivity OnCreate method like this:
There should be more details than that if you run in a debugger but the first thing to do would be to ensure that all your projects are on the same version of Couchbase. A version mismatch can sometimes cause this.
Ah yes you’re right if I dive into the exception there is a {System.DllNotFoundException} InnerException:
at (wrapper managed-to-native) LiteCore.Interop.NativeRaw.c4_getVersion()
at LiteCore.Interop.Native.c4_getVersion () [0x00000] in C:\Jenkins\workspace\couchbase-lite-net-edition-build\couchbase-lite-net-ee\couchbase-lite-net\src\LiteCore\src\LiteCore.Shared\Interop\Common\C4Base_native.cs:109
at LiteCore.Interop.LiteCoreImpl.c4_getVersion () [0x00000] in C:\Jenkins\workspace\couchbase-lite-net-edition-build\couchbase-lite-net-ee\couchbase-lite-net\src\LiteCore\src\LiteCore.Shared\Interop\LiteCore_impl.cs:41
at Couchbase.Lite.Interop.Native.c4_getVersion () [0x00000] in C:\Jenkins\workspace\couchbase-lite-net-edition-build\couchbase-lite-net-ee\couchbase-lite-net\src\LiteCore\src\LiteCore.Shared\Interop\LiteCore_shell.cs:43
at Couchbase.Lite.Sync.HTTPLogic.GetUserAgent () [0x00152] in C:\Jenkins\workspace\couchbase-lite-net-edition-build\couchbase-lite-net-ee\couchbase-lite-net\src\Couchbase.Lite.Shared\Sync\HTTPLogic.cs:239
at Couchbase.Lite.Sync.HTTPLogic..cctor () [0x00000] in C:\Jenkins\workspace\couchbase-lite-net-edition-build\couchbase-lite-net-ee\couchbase-lite-net\src\Couchbase.Lite.Shared\Sync\HTTPLogic.cs:47
I’m using Couchbase.Lite 2.1.1 across all projects (Forms/Android/iOS) and I’ve added Couchbase.Lite.Support.Android/Couchbase.Lite.Support.iOS to Android/iOS projects.
Not quite known but mentioned before. I’m not sure why x86 is not enough for it (x64 should be capable of running x86 native libs, but maybe if the runtime is 64-bit then maybe it’s now requiring x64)