Using Dapper (or other NuGet packages) with Xamarin Android - xamarin

I am currently working on a Xamarin.Android project for a FieldService app. I looked into the standard Xamarin SQLite.NET component for the Data Access Layer, but it does not meet my needs. (I cannot create a PK with multiple fields, for example).
I tried to use the Dapper framework, since I have more experience with that and I think it's pretty awesome.
Couldn't get it to work with Xamarin.Android. I am using Xamarin with Visual Studio 2013. Anyone who knows how to do this?
I tried 3 ways:
Adding Dapper to a Xamarin.Android Class Library. - No errors, but Dapper was not under the References group in solution explorer and I couldn't use the namespace Dapper
Adding Dapper to a "normal" .net Class Library. - Everything worked, I was able to add it, I could use the Dapper namespace and Query methods etc. BUT there was an error referencing the project to the main Xamarin.Android application project. (different target framework)
Adding Dapper to a Portable Class Library targeting .NET Framework 4.5 and Xamarin.Android. - Error when adding the NuGet package.
Brief question: How to add Dapper (or other NuGet packages) to Xamarin.Android?
Thanks in advance.

The Dapper NuGet package contains assemblies that target:
.NET 3.5
.NET 4.0
.NET 4.5
So you will not be able to the NuGet package with an Xamarin Android project since this project will target MonoAndroid.
Dapper would need to be recompiled against the MonoAndroid target framework, if possible. Otherwise you would need to look at other alternatives.
Looking at the Dapper GitHub site all the various classes available in the NuGet package are from one SqlMapper.cs file which seems to compile inside an Android project.

Related

xamarin forms socketioclientdotnet

I'm not sure if this is a Visual Studio issue or a genuine incompatibility but trying to install SocketIoClientDotNet into a Xamarin forms PCL project I get
Could not install package 'SocketIoClientDotNet 1.0.6'. You are trying to install this package into a project that targets '.NETPortable,Version=v4.5,Profile=Profile7', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
The project targets .NetFramework 4.5 which seems to be supported by the package - what could be going wrong here?
I suggest you add the following packages in your .Droid and .iOS projects (and not in the "common" project):
EngineIoClientDotNet (v.0.9.22)
SocketIoClientDotNet (v.0.9.13)
WebSocket4Net (v.0.14.1)
These versions of packages were the stablest 6 months ago when I had to use sockets in my project. If you want more information don't hesitate to ask me!

Using FluentMigrator in a Xamarin Portable Class Library

I have created a Xamarin Forms project within VS 2017 Community Edition. I would like to use FluentMigrator to create a a database for use within the application.
When I attempt to use NuGet PM to install FluentMigrator into the project, I get the following error:
Could not install package 'FluentMigrator 1.6.2'. You are trying to install this package into a project that targets '.NETPortable,Version=v4.5,Profile=Profile259', but the package does not contain any assembly references or content files that are compatible with that framework. For more
information, contact the package author.
I am guessing it's the fact that my project is using.NETPortable.
Is it possible to use FluentMigrator within a Xamarin PCL? If so, what needs to be changed in my project configuration?
The FluentMigrator does not have any assemblies that are compatible with PCL projects. It contains two lib directories: 35 and 40. These seem to have .NET assemblies for .NET 3.5 and .NET 4.0. So you cannot install this into a PCL project.
I would instead see if you can just create a .NET project, say targeting .NET 4.5, and install the FluentMigrator NuGet package into that project and define your migrations there.

Xamarin Forms and Entity Framework Core NetStandard

Recently Xamarin announced support for NetStandard (see https://releases.xamarin.com/stable-release-cycle-7-service-release-1/) and the recently shipped Entity Framework Core supports NetStandard. There was a recent issue with the SQLite.Native package that has been resolved (see https://github.com/aspnet/EntityFramework/issues/4269) but when I build the Android version of a Xamarin Forms application it appears it does not include all the assemblies in the output that are needed by the Entity Framework and therefore the application will not run and crashes on the first line of EF code to retrieve data. The UWP version appears to work just fine so this seems like an issue with Android (possibly iOS too).
Has anyone run into this and know a way around it so that the compiled Xamarin Forms Android application will run using Entity Framework Core to access a SQLite database?
Thank you in advance.
Here are the steps you can follow.
Create a Xamarin.Forms project.
Convert the PCL project's properties to .NET Standard 1.3
Install Entity Framework Core and other EF Core stuffs
I have prepared a small hello world project at Github Here.
need to use -linkskip to inform compiler not to remove references.

Can not compile after migrating unified api in xamarin forms

We have migrated the xamarin forms project to unified api.
But we have the strange compile error like this:
Could not AOT the assembly '.../iOS/obj/iPhone/Debug/mtouch-cache/Build/Xamarin.Forms.Labs.dll
So I changed the settings in iOS project's options.
In ios Build Tab of Project options(iOS) I changed the "don't link" to "Link all assemblies".
But the app is crashed when it is started.
xamarin version is 5.7.1(build 17).
xamarin forms's version is 1.3.5.6337.
xamarin forms labs's version is 1.0.1.5.
Please help me if you have the experience with this error.
Replace Xamarin.Forms.Labs with XLabs.Forms.
There has been a major refactoring on how the XLabs project is structured so your existing project based on the 1.x.x will break. The reason for the refactoring was simple; separate functionality that does not depend on Xamarin.Forms into different assemblies. This allows the use of functionality like IoC, Serialization and even platform specific services without referencing XF.
To upgrade:
Uninstall any existing Xamarin.Forms.Labs packages from your
project.
Install XLabs.Forms package to your projects (PCL, iOS, Droid & WP). This will update Xamarin.Forms to the latest stable release (1.4.x)
Refactor code to reference the correct namespaces.

Can I add .NET 3.5+ NuGet packages to a Mono for Android project?

Mono for Android has access to most of .NET 4.0 from the Mono framework. Unfortunately, when I try to add NuGet packages in Visual Studio that specifically target .NET 3.5 or beyond, with a /lib/net*/ folder structure, it tosses up an error.
You are trying to install this package into a project that targets
'MonoAndroid,Version=v2.1', but the package does not contain any
assembly references that are compatible with that framework.
If a NuGet package doesn't have the .NET version breakdown, or one where you removed that subdirectory structure and published it to a NuGet source, it works fine. For example, NUnit just has a /lib/ folder with no further breakdown by .NET framework version and installed fine.
It appears NuGet could be checking compatibility by using the <TargetFrameworkVersion> project file XML element. If so, that is the problem as Mono for Android usurps that element to mean a "target Android framework version". For example, to target Android v2.2, it looks like this:
<TargetFrameworkVersion>v2.1</TargetFrameworkVersion>
In the project properties dialog, where the "[.NET] Target framework" drop-down would be is a drop-down for "Minimum Android to target" that affects this XML element.
If this is the problem NuGet is encountering, I won't be able to use unmodified NuGet for version-specific packages until targeting an Android app for a minimum of Ice Cream Sandwich (v4.0).
Side note
You can reference the DLLs from these packages via project reference. It definitely throws a warning at you, but you can ignore it fairly safely (assuming the assembly doesn't wander too far from the code implemented in Mono).
'Some.dll', or one of its dependencies, requires a later version of
the .NET Framework than the one specified in the project...
No, assemblies must be compiled against the 2.0.5 profile in order to be used by Mono for Android. You can achieve this by using the Mono for Android Class Library template or by using assemblies compiled for Silverlight.
The Android version (2.2, 3.0, 4.0) is not related to the version of the .NET BCL an assembly is compiled against.

Resources