1

I'm new to android and xamarin. Recently I have created one android app following xamrarin sample TaskyPortable. Problem is whenever following code executes it throws error.

        public override void OnCreate()
        {
            base.OnCreate();
            var sqliteFilename = "ToDoItemDB.db3";
            string libraryPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
            var path = Path.Combine(libraryPath, sqliteFilename);
            conn = new SQLiteConnection(path);

whenever it calls new SQLiteConnection with given path, it throws

"System.TypeInitializationException: The type initializer for 'SQLite.SQLiteConnection' threw an exception."

What am I doing wrong? The code is almost similar to TaskyPortable. I have searched a lot but did not find anything.

Kindly help.

P.S. : This question is already asked here and I have checked the answer. I have added reference of SQLite.net in droid project also. But still facing this issue.

1
  • Your code is Xamarin Android code, but the example and question is Xamarin PCL project. Can you confirm which kind of project you are using? Xamarin PCL or Xamarin Andorid? Commented Mar 27, 2017 at 7:39

2 Answers 2

1

This code is working

  private SQLiteConnection conn;      

  protected override void OnCreate(Bundle bundle)
  {
   base.OnCreate(bundle);
   Forms.Init(this, bundle);

   var sqliteFilename = "ToDoItemDB.db3";
   string libraryPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
   var path = Path.Combine(libraryPath, sqliteFilename);
   conn = new SQLiteConnection(path);

   //create table
   conn.CreateTable<Todo>();

   LoadApplication(new App());
  }

Check if those packages are in the package.config. Maybe is better to remove the Sqlite packages and install only the sqlite-net-pcl, which is installing the rest of the sqlite packages

  <package id="sqlite-net-pcl" version="1.3.1" targetFramework="monoandroid60" />
  <package id="SQLitePCLRaw.bundle_green" version="1.1.2" targetFramework="monoandroid60" />
  <package id="SQLitePCLRaw.core" version="1.1.2" targetFramework="monoandroid60" />
  <package id="SQLitePCLRaw.lib.e_sqlite3.android" version="1.1.2" targetFramework="monoandroid60" />
  <package id="SQLitePCLRaw.provider.e_sqlite3.android" version="1.1.2" targetFramework="monoandroid60" />
Sign up to request clarification or add additional context in comments.

Comments

0

I had encountered same error. In my case, mysql.Data package crashed. After delete mysql.Data package it solved.

3 Comments

This should have been shared more as a comment on the issue rather than an answer to ease the task of other users finding the solution.
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.