question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug] On iOS: The type initializer for 'SQLite.SQLiteConnection' threw an exception (Android works)

See original GitHub issue

Description

  public class Database
  {
      public Database()
      {
          var dbPath = Path.Combine(FileSystem.AppDataDirectory, "databaseTest.db3");

          Connection = new SQLiteAsyncConnection(dbPath);
          Connection.CreateTableAsync<User>().Wait();
      }

      public SQLiteAsyncConnection Connection { get; set; }
  }

This seems to work fine with Android applications allowing me to manipulate the database from anywhere.

However, when I run this application through an IOS simulator with an active Mac connection I get the following error:

“The type initializer for ‘SQLite.SQLiteConnection’ threw an exception.”

I believe that an active connection to an SQLite database cannot be resolved but I don’t know why.

Steps to Reproduce

  1. Create a database class that uses SQLite-net-plc to establish a connection with a database in the constructor
  2. Pass this class through the MAUI dependency injection

Expected Behavior

Database connection connects and you can use the database

Actual Behavior

“The type initializer for ‘SQLite.SQLiteConnection’ threw an exception.”

Basic Information

  • Version with issue: 6.0.101-preview.9.1843
  • Last known good version: n/a
  • IDE: VS 2022
  • Platform Target Frameworks:
    • iOS: 15.0
    • Android: n/a
    • UWP: n/a
  • Android Support Library Version: n/a
  • Nuget Packages: sqlite-net-plc, SQLitePCLRaw.provider.dynamic_cdecl
  • Affected Devices: Iphone 11 Pro Max IOS 15.0

Screenshots

n/a

Reproduction Link

not available

Workaround

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:16 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
RaspeR87commented, Feb 2, 2022

@VladislavAntonyuk no, I am talking about VS and MAUI on Windows and remote debugging on remote iOS simulator via Mac

By the way what is your iOS version?

iOS 15.2

0reactions
VladislavAntonyukcommented, Feb 11, 2022

It is fixed. I update the sample app. Please try again

Read more comments on GitHub >

github_iconTop Results From Across the Web

The type initializer for 'SQLite.SQLiteConnection' threw an ...
I had the issue of 'SQLite.SQLiteConnection' exception when running on iOS. I installed the Beta Version of sqlite-net-pcl version 1.9.141-beta, ...
Read more >
Problem with running my program on Android : r/dotnetMAUI
Hello guys! I am trying to make an app that uses SQLite for the database. It is a simple database, the elements made...
Read more >
VS2019 the type initializer for 'sqlite.sqliteconnection' threw ...
I am building a Xamarin.Forms application and deploying to Android. The application when built from VS2017 run fine.
Read more >
The type initializer for System.Data.SQLite.SQLiteFactory ...
TypeInitializationException : The type initializer for 'System.Data.SQLite.SQLiteFactory' threw an exception. ---> System.DllNotFoundException: Unable to ...
Read more >
Question - SQLite: SqliteConnection.Open() causes ...
I suspect that the error message might be misleading and the problem can be with the path to the database (it is located...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found