Solved: SQLite PCL TypeInitializationException
For those that get this error and just want the quick fix, here it is:
Open 'References' in your project and proceed to remove all references to SQLite from the list. Once that's done, right click the project and click 'Manage Nuget Packages...', from here, click the 'Installed' tab and then Uninstall all SQLite packages, then search for sqlite-net-pcl and install the one by 'Frank A. Krueger' this will install with it all the other dependencies for that package along with it.
But why?
As to why this has happened, I can only assume it's down to references to older versions of files or references that are no longer required getting left in the project after a package upgrade or uninstall.
Where and other thought processes
The 'TypeInitializationException' error normally happens on a line like the following:
var conn = new SQLiteConnection(path);
And this makes it look like it's a problem with the path or write access to the device but I assure you it's not. It's definitely a dependency.
Happy coding!
Published at 22 Nov 2016, 13:16 PM
Tags: SQL,SQLite,Xamarin,PCL