Couchbase.Lite in Xamarin Forms app System.TypeInitializationException

.net

#1

Hi

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:

Couchbase.Lite.Support.Droid.Activate(ApplicationContext);

The only exception details I get are:

System.TypeInitializationException: The type initializer for 'Couchbase.Lite.Sync.HTTPLogic' threw an exception.

Is there something I’m missing?

Thanks for any help :slight_smile:


#2

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.


#3

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.


#4

OK this looks like it’s only an issue when running on an emulator.
Building and debugging the same code on a physical device and everything works fine :thinking:


#5

Is this an x64 emulator by any chance (as opposed to x86)?


#6

It is indeed, is there a known issue?


#7

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)