[Bug] On iOS: The type initializer for 'SQLite.SQLiteConnection' threw an exception (Android works)
See original GitHub issueDescription
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
- Create a database class that uses SQLite-net-plc to establish a connection with a database in the constructor
- 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:
- Created 2 years ago
- Comments:16 (9 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
iOS 15.2
It is fixed. I update the sample app. Please try again