Xamarin.forms Cross platform Oct. 2017

Hi,

We are in the middle of october 2017, Is it possible to use couchebase in a new Xamrin.forms, cross platform, shared library project ?

Do I have to add a special nuget’s url ?

When I’m trying to add CouchBase.lite package, version 1.4, nuget work fine with the .android et the .ios’s project, but failed with le .UWP’s project.

I’m trying to make a “proof of concept”, so what I am missing ?

I just installed visual studio community adn started a new Xamarin cross-platforms, c# shared library project.

Regards,

Steeve

There are no plans to make the 1.x line compatible with UWP. The supported platforms are .NET 3.5+ and Xamarin. 2.0 has UWP support and is nearing feature completion. You can try it if you like by adding http://mobile.nuget.couchbase.com/nuget/Developer as a feed source.

Hi,

Thank you for your answer.

I started a new project xamrin.forms cross platform, shared library. Test Ok
Update the nuget packages, Test the application, OK

Added the feed source “mobile.nuget.couchbase.com/nuget/Developer”, and add CouchBase.lite V2.0.0-db018.
rebuild the solution, test the app : OK

I’m trying to follow this doc :Couchbase Capella for Mobile Developers
Where to call the Activate fonction ?

I tried the database step in this doc, but I’ve an exception with : var database = new Database(“my-database”);

How to start ? Is there an working exemple ?

Regards

Seeve

I imagine the exception is because of the lack of Activate() call. You need to call it somewhere early on in your app lifecycle, and just once. So perhaps the static constructor for your application? It needs to be called before any other function is used.

An example is kept here.

Hi again,

Thank you for your hlep.

After some check, the “Activate” methode is well called before the creation of the database.
I put the call into the UWP project.

I’m trying to create the database into the Shared project, following your exemple.

Here is the exception :

slight_smile:L’exception System.TypeInitializationException s’est produite
HResult=0x80131534
Message=The type initializer for ‘Couchbase.Lite.Database’ threw an exception.
Source=<Impossible d’évaluer la source de l’exception>
Arborescence des appels de procédure :
à Couchbase.Lite.Database…ctor(String name, DatabaseConfiguration configuration)
à CouchbaseTest.MainPage…ctor() dans C:\Projets\CouchbaseTest\CouchbaseTest\CouchbaseTest\MainPage.xaml.cs :ligne 19
à CouchbaseTest.App…ctor() dans C:\Projets\CouchbaseTest\CouchbaseTest\CouchbaseTest\App.xaml.cs :ligne 16
à CouchbaseTest.UWP.MainPage…ctor() dans C:\Projets\CouchbaseTest\CouchbaseTest\CouchbaseTest.UWP\MainPage.xaml.cs :ligne 24
à CouchbaseTest.UWP.CouchbaseTest_UWP_XamlTypeInfo.XamlTypeInfoProvider.Activate_4_MainPage() dans C:\Projets\CouchbaseTest\CouchbaseTest\CouchbaseTest.UWP\obj\x86\Debug\XamlTypeInfo.g.cs :ligne 207
à CouchbaseTest.UWP.CouchbaseTest_UWP_XamlTypeInfo.XamlUserType.ActivateInstance() dans C:\Projets\CouchbaseTest\CouchbaseTest\CouchbaseTest.UWP\obj\x86\Debug\XamlTypeInfo.g.cs :ligne 427

Exception interne 1 :
TypeInitializationException : The type initializer for ‘Couchbase.Lite.Sync.HTTPLogic’ threw an exception.

Exception interne 2 :
FileLoadException : Could not load file or assembly ‘System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’. The located assembly’s manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Is that talking to you ?

Regards,

Steeve

I have not encountered that error before, but I have also not tried to build a setup quite like that one yet. The message is saying that it cannot find a dependent DLL that is supposed to be present in the UWP installation because it looks like it is looking for the .NET Core one.

To sanity check, you have installed the UWP version of the support library and called Couchbase.Lite.Support.UWP.Activate() right, not the same one as in the example (since the example is .NET Core)? I don’t think it should be possible to call the other one but you never know.

I just set up a project that I think is similar to the way yours is and it works as expected. I was able to create a database inside of the “shared library” (another .NET Standard library that I linked with the UWP application That .NET Standard library and the UWP application are both linked to Couchbase Lite). Have you tried doing a clean and rebuild?

Hi Jim,

Thank you again for your help.

I spend 3 hours testing, on android et UWP, always some problems.

I called well the good Activate function :
UWP => Couchbase.Lite.Support.UWP.Activate();
Android => Couchbase.Lite.Support.Droid.Activate(this);

For android, Xamarin live player give me that in the log :
Could not find type ‘LiteCore.Interop.C4DatabaseObserver" in Couchbase.Lite’

For Uwp, always the same exceptions. When I try not to call the Activate function, I’ve another exception. So, I think it’s well called. In debug with a break point, I first pass the Activate function, before create the DataBase.

I tried a new solution with the framework in version 4.7. My forst solution was in 4.6.1. this too solution are Xamarin cross platforms, Shared library, Blank solution.

I’ve Vs 2017 in version 15.4.

I don’t know what to do now.

Regards.

Steeve

Hmmm, maybe I am missing a dependency in the nuspec and I never noticed because it was already present, but try adding System.Runtime.InteropServices.RuntimeInformation from Nuget.

Nice,

It’s working.
I needed to update System.Runtime.InteropServices.RuntimeInformation in version 4.3.
No more exceptions.

I will be able to push forward.

Thank you.

regards.

Steeve

Hi,

Now I’ve a code that work fine with the UWP projet. I call the Activate function, create the Database et write and read a document.

But I always have an exception in Android’s project :
Could not find type ‘LiteCore.Interop.C4DatabaseObserver’ in Couchbase.Lite’

How can I correct this problem ?

Regards,

Steeve

Hi,

After testing in IOS, I’ve the same problem :
Could not find type ‘LiteCore.Interop.C4DatabaseObserver’ in Couchbase.Lite’

Regards,

Steeve

This sometimes happens when an unexpected version of a library is found in .NET. The error message is quite unhelpful, but if you are using a middle library then make sure everything is using the same versions of Couchbase.Lite and the support libraries. Also make sure that your app has both packages installed on it even if it is also installed in the middle library.

HI,

Thank you to spend some time to answer me. I appreciate that very much.

Unfortunately, you completely lost me, I don’t understand what do you mean with “middle Library” and “make sure that your app has both packages installed on it”.

May I ask you to give me some path to follow ?

Regards,

Steeve

I thought by “shared library” you meant some intermediate library. Do you mean shared project instead? If you look in the repo you will find Couchbase.Lite.Tests.Android (and iOS) which utilize the package without the errors you mentioned. I wonder if those will work for you if you add the db packages to them?

Hi,

In fact I’m an old developer in asp.net and c#, I still am, but I’m new with Xamarin.

Since the last version of Vs 2017 (15.4) et the last version of Xamarin.forms 2.4.0.282, when you create a new project, you have to choose between PCL or “Shared Library”. Furthermore, I read that PCL is obsoled, So I create my projects with the default mode : Shared Library.

I read about “Shared project”, but I can’t select anymore. Never tested it.

My goal is to know if this very new tech is usable. I want to know if I can make an app, running on Windows Desktop, and tablette, Android Tablette and phone, IOS Tablette and phone and Mac Desktop, having a “offline mode” (local storage) and sync between all of this devices when the connection came up. Exactly as Google Agenda.

That’s why I’m testing Coachbase.

I hope this will help you to understand my test case. Did you test the same senario ?

Regards,

Steeve

PS : I’m french.

Your French exception messages above hinted that you were French :wink: . My goal is to be able to use Couchbase Lite in as many places as possible so I have set up shared code that runs on all of the platforms you mentioned (although Mac Desktop is through .NET Core, not Xamarin Mac. Couchbase Lite does not support Xamarin Mac, although it could if the right community user were interested, it wouldn’t take much work to build it, but we don’t have enough resources to test it).

You are right that PCL is obsolete, but it has been replaced with something better: .NET Standard. If you write a .NET Standard assembly, you can run it on many platforms both currently existing, and in the future. My suggestion is to write your code as a .NET Standard library and reference Couchbase.Lite from it. Couchbase.Lite itself is a .NET Standard library, but unfortunately the cross platform API coverage is not quite enough and so I use dependency injection to reach the rest (that is the reason for the call to Activate()). For automated testing, each build gets tested inside of a UWP test application, an iOS test application, an Android test application, and as a console program on Windows, Linux, and Mac. So I think you can see why it is confusing to me for the library to fail in such a basic way.

Usually with messages like that, it has to do with differing versions of a library being referenced in different places.

As for your question, as I mentioned having an offline first database with built in sync capabilities across platforms is the main goal of the project. It has been around since 2011, so the project itself it not exactly new (or were you referring to something else?), and 2.0 has been in development now for almost a year. It is pretty much feature complete for the 2.0 milestone, with API scrutiny and performance enhancements / functional testing coming in the final months.

Ok,

Thank you again for all this informations.

I will try as you say, a .NET standard Library.

But not until a week, I’ve badly some other work to do.

Regards,

Steeve