I have a Xamarin Project that uses the new .NET Standard. In the shared .NET Standard project I would like to add Couchbase Lite 2.0 which I have installed via nuget.
The problem is when I call the var db = Database.Exists("my-database"); it gives an error because it needs the Couchbase.Lite.Support.UWP.Activate(); called first. But this is not possible in the shared .NET Standard project. Of course it works if I place the couchbase code in the UWP, iOS or Android Project.
My goal was to have the shared .NET Project have all of the couchbase code there, not repeat the same cond in each UWP, iOS and Android Projects in xamarin.
I’m trying to do excactly the same project, without full success for now.
I tried to call the respective Activate function in each projects, It worked in UWP, but not Android and Ios, thru Xamrin live player.
You can find my post here : Xamarin.forms Cross platform Oct. 2017
May you tell me how you are doing it ? Version of Visual studio, version of Couchbase, maybe some examples …
I had to reformat my computer and I have been installing back all of my programs. I will re-create a test project and update. Originally I also had issues with the Android project but did get it to work.
Thank you for your answers, I’m feeling less alone in the dark !
I did preety the same as you, but it’s steal not working.
1°) What’s your target framework (API) version for your .Net Standard Library ? I kept mine with the default version 1.4.
2°) For the android project, you talked about the OnCreate(), I assume you’re talking about the MainActivity file. Is that True ?
I did add the same line Couchbase.Lite.Support.Droid.Activate(this); in this file, but before the LoadApplication (…); Did you do the same, or called Couchbase.Lite.Support.Droid.Activate(this); after LoadApplication (…) ?
1 -I also have the .NET Standard set to version 1.4
2 - Yes for the Android Project, the OnCreate() in the MainActivity
3 - I am assuming you added the .NET Standard project reference to the Android Project?
Firstly, I learned that you have 4 projects in your solution, like if you started your solution with PCL library, and changed it to become a shared librabry project.
Secondly, I compiled it without trouble, but I had an exception when running the android project. It can’t find de library for the .Net Standard project. As always, when I add a .Net standard library in my solution, I’ve no trouble to add the reference, et no trouble to compile, but the app fail to run, as if the DLL was not send to the device, thru xamarin live player.
It’s very strange. I did try with my personnal computer too, installed a fresh VS2017 V15.4.1, create a new shared library solution+project, just added a .net standard library + reference + call of a method, same result : Exception reference not found.
If it’s working for you, I’m propably missing something, but what ?
I think you are already doing this but let’s double check. Select the .NET Standard Project and Right Click. Then Click on Properties. Under the Application Settings is the Target framework set to .NET Standard 1.4? My Output type is Class Library.
Yes, I actually started with a New Shared Project Xamarin Application. Then I added a new project as .NET Standard 2.0. Then I moved the Shared Project Files to .NET Standard project and deleted the Xamarin Shared Project. I made sure the iOS, Android and UWP Projects had reference to the .NET Standard Project.
When I run the Android Project I am using the Android 7.1 API 25.
If I can think what might be causing your error I will update this post.
I followed the instructions at developer.xamarin in order to change the Shared/PCL project to .NET Standard 2.0. They instruct to remove it and add that logic to the new .NET Standard 2.0 project.
If you download the new Visual Studio 2017 Preview when you create new Xamarin project the .NET Standard 2.0 is an option. The link is https://www.visualstudio.com/vs/preview/
A new version of Xamarin Live player made possible to use a .net standard library into the solution.
This work well under Android, but not under Ios, yet.
Marco, Did you try your testApp thru Xamarin Live player, and with a real Android physical device? Did you try to make it work UWP platform?
I’m always bloked by the problem that the couchbase lite library (and dependencies) are not send to xamarin live player, even with the latest version (for info: 1.2.80 on android). (for info : No problem to compile).