Resolving SQLite issues for .NET MAUI
Recently, while working on ExampleApp, we faced two significant errors and found effective solutions for both. Here’s a detailed account of the problems and their resolutions.
System.TypeInitializationException
System.TypeInitializationException: The type initializer for 'SQLite.SQLiteConnection' threw an exception.
---> System.DllNotFoundException: e_sqlite3
To resolve this error, we needed to install the latest NuGet package for SQLitePCLRaw.bundle_green
. This package ensures that the necessary SQLite libraries are included in the project.
Add the following package reference with the latest version to your project:
<PackageReference Include="SQLitePCLRaw.bundle_green" Version="2.1.10" />
In the AppDelegate.cs
file, add the following line to the CreateMauiApp
method:
protected override MauiApp CreateMauiApp()
{
SQLitePCL.raw.SetProvider(new SQLitePCL.SQLite3Provider_sqlite3());
return MauiProgram.CreateMauiApp();
}
System.ExecutionEngineException
in iOS Release Mode
System.ExecutionEngineException: Attempting to JIT compile method '(wrapper delegate-invoke) void System.Action`2<ExampleApp.Entites.LocalDatabase.VoucherLite, double>:invoke_callvirt_void_T1_T2 (ExampleApp.Entites.LocalDatabase.VoucherLite,double)' while running in aot-only mode. See https://docs.microsoft.com/xamarin/ios/internals/limitations for more information.
This error occurs due to the JIT compilation attempt in AOT-only mode on iOS. The solution is to install this specific version of the sqlite-net-pcl
.
It will ONLY work with 1.7.355 or below.
<PackageReference Include="sqlite-net-pcl" Version="1.7.335" />
This solution is also applicable to Xamarin projects.
Tags In
Leave a Reply Cancel reply
This site uses Akismet to reduce spam. Learn how your comment data is processed.
Hi, I am András,
I am a seasoned software engineer from Budapest, Hungary with a strong focus on mobile app development using .NET MAUI and Xamarin.Forms. My expertise also extends to website building for my happy customers and other complex system designing. I am passionate about developing well-organized, maintainable software solutions.