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

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

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 16 (9 by maintainers)

Most upvoted comments

@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