Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin SQLite "This is the 'bait'"

Tags:

sqlite

xamarin

I follow this guide trying to create a SQLite database to my proyect. But always got same error, doing the exactly steps of the article.

    System.Exception: This is the 'bait'.  You probably need to add one of the SQLitePCLRaw.bundle_* nuget packages to your platform project.
like image 237
Efeyabel Avatar asked Dec 27 '16 11:12

Efeyabel


3 Answers

Have you added the SQLite package to all your projects? You need to add it to the app projects as well as the PCLs.

This is what the error is telling you. It uses a trick called 'bait and switch' whereby it installs a dummy assembly in the PCL with a particular interface, and in the Android and iOS apps it installs a platform specific assembly with an identical interface that actually does the interactions with the database. The idea is you code against the PCL, but at run time the platform specific version of the library is used. You can read more about this pattern at https://web.archive.org/web/20161209075521/http://log.paulbetts.org/the-bait-and-switch-pcl-trick/

Essentially though, this error is telling you that you haven't installed the NuGet package in your platform-specific projects.

like image 168
JimBobBennett Avatar answered Oct 19 '22 23:10

JimBobBennett


I was experiencing this issue despite following the instructions in the error message and installing the missing library.

A clean & rebuild solved it

like image 39
James Wierzba Avatar answered Oct 20 '22 00:10

James Wierzba


I had installed the packages (SQLite-net PCL) but I uninstalled them, then reinstalled. And then I cleaned the solution and rebuilded it and now it works.

like image 20
maracuja-juice Avatar answered Oct 20 '22 00:10

maracuja-juice