Using Dapper (or other NuGet packages) with Xamarin Android

dapper nuget xamarin xamarin.android

Question

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:

  1. 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

  2. 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)

  3. 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.

Accepted Answer

The Dapper NuGet package contains assemblies that target:

  1. .NET 3.5
  2. .NET 4.0
  3. .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.




Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why