Search code examples
xamarinsqlite-net-pcl

How to avoid AggregateException that contains a TypeInitializationException when creating a table with sqlite


In my DB ctor:

databasePath = GetPath(docsFolder);
connection = new SQLiteAsyncConnection(databasePath);
connection.CreateTableAsync<BO>().Wait();

Database path is /data/user/0/com.companyname.AppName/files/fn.db3 (Package name filtered only here)

But that occurs when creating a table: Unhandled Exception: System.AggregateException: One or more errors occurred.

In BO I removed already DateTime: Currently only string and int are types that are applied.

public class BO
{
        [PrimaryKey, AutoIncrement]
        public int ID { get; set; }

        public string From { get; set; }

        public string To { get; set; }

        public string Note { get; set; }
}

NuGet:

  <package id="sqlite-net-pcl" version="1.4.118" targetFramework="portable45-net45+win8+wpa81" />
  <package id="SQLitePCLRaw.bundle_green" version="1.1.5" targetFramework="portable45-net45+win8+wpa81" />
  <package id="SQLitePCLRaw.core" version="1.1.5" targetFramework="portable45-net45+win8+wpa81" />

EDIT: In the AggregateException is one TypeInitializationException, which occurs when creating the table. But SQLite.SQLiteConnection is stated as TypeName concerning the TypeInitializationException when debugging. SQLiteAsyncConnection connection was clearly defined in the code. Is there a privilege missing to create a db file?


Solution

  • 2 packages were missing within the Android project.

    SQLitePCLRaw.lib.e_sqlite3.android
    SQLitePCLRaw.provider.e_sqlite3.android